Skip to content

Commit a8d2791

Browse files
committed
Fix SlurmFlag Enum and ReservationReoccurrence Enum (#374)
* fix accidentally importing StrEnum * We can't use auto with multiple other values after it, sadly. Due to a bug in stdlib Enum, that is only fixed in 3.11 and 3.12 * fix SlurmFlag for Python < 3.10 (cherry picked from commit ff205f7) (cherry picked from commit e172b3d)
1 parent 21b7a59 commit a8d2791

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

pyslurm/core/reservation.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ from datetime import datetime
3232
from pyslurm import xcollections
3333
from pyslurm.utils.helpers import instance_to_dict
3434
from pyslurm.utils.enums import SlurmEnum, SlurmFlag
35-
from enum import auto, StrEnum
35+
from enum import auto
3636
from pyslurm.utils.ctime import (
3737
_raw_time,
3838
timestr_to_mins,
@@ -575,9 +575,9 @@ class ReservationReoccurrence(SlurmEnum):
575575
576576
See {scontrol#OPT_Flags} for more info.
577577
"""
578-
NO = auto()
579-
DAILY = auto(), slurm.RESERVE_FLAG_DAILY, slurm.RESERVE_FLAG_NO_DAILY
580-
HOURLY = auto(), slurm.RESERVE_FLAG_HOURLY, slurm.RESERVE_FLAG_NO_HOURLY
581-
WEEKLY = auto(), slurm.RESERVE_FLAG_WEEKLY, slurm.RESERVE_FLAG_NO_WEEKLY
582-
WEEKDAY = auto(), slurm.RESERVE_FLAG_WEEKDAY, slurm.RESERVE_FLAG_NO_WEEKDAY
583-
WEEKEND = auto(), slurm.RESERVE_FLAG_WEEKEND, slurm.RESERVE_FLAG_NO_WEEKEND
578+
NO = "NO"
579+
DAILY = "DAILY", slurm.RESERVE_FLAG_DAILY, slurm.RESERVE_FLAG_NO_DAILY
580+
HOURLY = "HOURLY", slurm.RESERVE_FLAG_HOURLY, slurm.RESERVE_FLAG_NO_HOURLY
581+
WEEKLY = "WEEKLY", slurm.RESERVE_FLAG_WEEKLY, slurm.RESERVE_FLAG_NO_WEEKLY
582+
WEEKDAY = "WEEKDAY", slurm.RESERVE_FLAG_WEEKDAY, slurm.RESERVE_FLAG_NO_WEEKDAY
583+
WEEKEND = "WEEKEND", slurm.RESERVE_FLAG_WEEKEND, slurm.RESERVE_FLAG_NO_WEEKEND

pyslurm/utils/enums.pyx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,15 @@ class SlurmEnum(str, Enum, metaclass=DocstringSupport):
8787
class SlurmFlag(Flag, metaclass=DocstringSupport):
8888

8989
def __new__(cls, flag, *args):
90-
obj = super()._new_member_(cls)
90+
parent = super()
91+
if hasattr(parent, "_new_member_"):
92+
# For Python >= 3.10, use _new_member_.
93+
# We could very likely just also use object.__new__, but it works
94+
# here, so no need to change it now.
95+
obj = parent._new_member_(cls)
96+
else:
97+
obj = object.__new__(cls)
98+
9199
obj._value_ = int(flag)
92100
obj._clear_flag = int(args[0]) if len(args) >= 1 else 0
93101
return obj

0 commit comments

Comments
 (0)