File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212import enum
1313import os
1414
15- from typing import Optional
15+ from typing import Optional , Union
1616
1717from .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
207200class KIND :
You can’t perform that action at this time.
0 commit comments