Skip to content

Commit cafbec5

Browse files
committed
refact: use Python's Enum in CONVENTION
1 parent 3fe87bd commit cafbec5

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

src/api/constants.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,25 +217,20 @@ def to_string(kind: 'KIND'):
217217
return kind.value
218218

219219

220-
class CONVENTION:
221-
unknown = None
220+
@enum.unique
221+
class CONVENTION(str, enum.Enum):
222+
unknown = 'unknown'
222223
fastcall = '__fastcall__'
223224
stdcall = '__stdcall__'
224225

225-
_NAMES = {
226-
unknown: '(unknown)',
227-
fastcall: '__fastcall__',
228-
stdcall: '__stdcall__'
229-
}
230-
231-
@classmethod
232-
def is_valid(cls, convention):
233-
return cls._NAMES.get(convention, None) is not None
226+
@staticmethod
227+
def is_valid(convention: Union[str, 'CONVENTION']):
228+
return convention in set(CONVENTION)
234229

235-
@classmethod
236-
def to_string(cls, convention):
237-
assert cls.is_valid(convention)
238-
return cls._NAMES[convention]
230+
@staticmethod
231+
def to_string(convention: 'CONVENTION'):
232+
assert CONVENTION.is_valid(convention)
233+
return convention.value
239234

240235

241236
# ----------------------------------------------------------------------

0 commit comments

Comments
 (0)