Skip to content

Commit 54997da

Browse files
committed
refact: use Python's Enum for SCOPEs
1 parent 409e966 commit 54997da

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

src/api/constants.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import enum
1313
import os
1414

15-
from typing import Optional
15+
from typing import Optional, Union
1616

1717
from .decorator import classproperty
1818

@@ -179,29 +179,22 @@ def to_type(typename: str) -> Optional['TYPE']:
179179
return None
180180

181181

182-
class SCOPE:
182+
@enum.unique
183+
class SCOPE(str, enum.Enum):
183184
""" Enum scopes
184185
"""
185-
unknown = None
186186
global_ = 'global'
187187
local = 'local'
188188
parameter = 'parameter'
189189

190-
_names = {
191-
unknown: 'unknown',
192-
global_: 'global',
193-
local: 'local',
194-
parameter: 'parameter'
195-
}
196-
197-
@classmethod
198-
def is_valid(cls, scope):
199-
return cls._names.get(scope, None) is not None
190+
@staticmethod
191+
def is_valid(scope: Union[str, 'SCOPE']):
192+
return scope in set(SCOPE)
200193

201-
@classmethod
202-
def to_string(cls, scope):
203-
assert cls.is_valid(scope)
204-
return cls._names[scope]
194+
@staticmethod
195+
def to_string(scope: 'SCOPE'):
196+
assert SCOPE.is_valid(scope)
197+
return scope.value
205198

206199

207200
class KIND:

0 commit comments

Comments
 (0)