Correct Python 3.7 compatibility hack

mypy complained about the signature of conditional def of get_args not matching the one from typing module, so I made it match, but apparently hadn't actually tested it with Python 3.7. It was just the return type hint, but it sill needs to parse at run time.

Also, fix up a few other (non-error) gripes from pylint.
This commit is contained in:
sparky8512 2022-09-09 11:01:53 -07:00
parent 5ff207ed8c
commit 1167742f75

View file

@ -352,10 +352,10 @@ try:
except ImportError:
# Python 3.7 does not have TypedDict, so fake it so the run time still
# works, even though static type checker probably will not.
def TypedDict(name, types):
def TypedDict(name, types): # pylint: disable=invalid-name
return type(name, (dict,), {"__annotations__": types})
def get_args(tp: Any) -> tuple[Any, ...]:
def get_args(tp: Any) -> Tuple[Any, ...]:
return tp.__args__
@ -483,11 +483,11 @@ _FIELD_NAME_MAP = {
def _field_names(hint_type):
return list(_FIELD_NAME_MAP.get(key, key) for key in get_type_hints(hint_type).keys())
return list(_FIELD_NAME_MAP.get(key, key) for key in get_type_hints(hint_type))
def _field_names_bulk(hint_type):
return list(key + "[]" for key in get_type_hints(hint_type).keys())
return list(key + "[]" for key in get_type_hints(hint_type))
def _field_types(hint_type):