Get config generation working with py3.10
The typing classes now have a __name__ attribute
This commit is contained in:
parent
2c0269930f
commit
68d2ea3f27
@ -39,17 +39,16 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]:
|
|||||||
imports: Set[Tuple[str, str]] = set()
|
imports: Set[Tuple[str, str]] = set()
|
||||||
tc_imports: Set[Tuple[str, str]] = set()
|
tc_imports: Set[Tuple[str, str]] = set()
|
||||||
|
|
||||||
def type_name(x: type) -> str:
|
|
||||||
ans = x.__name__
|
|
||||||
if x.__module__ and x.__module__ != 'builtins':
|
|
||||||
imports.add((x.__module__, x.__name__))
|
|
||||||
return ans
|
|
||||||
|
|
||||||
def option_type_as_str(x: Any) -> str:
|
def option_type_as_str(x: Any) -> str:
|
||||||
if hasattr(x, '__name__'):
|
needs_import = False
|
||||||
return type_name(x)
|
if type(x) is type:
|
||||||
ans = repr(x)
|
ans = x.__name__
|
||||||
ans = ans.replace('NoneType', 'None')
|
needs_import = True
|
||||||
|
else:
|
||||||
|
ans = repr(x)
|
||||||
|
ans = ans.replace('NoneType', 'None')
|
||||||
|
if needs_import and getattr(x, '__module__', None) and x.__module__ not in ('builtins', 'typing'):
|
||||||
|
imports.add((x.__module__, x.__name__))
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def option_type_data(option: Union[Option, MultiOption]) -> Tuple[Callable[[Any], Any], str]:
|
def option_type_data(option: Union[Option, MultiOption]) -> Tuple[Callable[[Any], Any], str]:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user