mirror of https://github.com/zulip/zulip.git
test_openapi: Drop Python 3.5 code in get_standardized_argument_type.
Also flip the Python 3.6 and 3.7+ cases to consider the modern version as the “normal” case. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
edaed497ed
commit
4d583e3d41
|
@ -369,41 +369,30 @@ so maybe we shouldn't mark it as intentionally undocumented in the urls.
|
||||||
E.g. typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType]
|
E.g. typing.Union[typing.List[typing.Dict[str, typing.Any]], NoneType]
|
||||||
needs to be mapped to list."""
|
needs to be mapped to list."""
|
||||||
|
|
||||||
if sys.version_info < (3, 7): # nocoverage # python 3.5-3.6
|
origin = getattr(t, "__origin__", None)
|
||||||
if sys.version_info < (3, 6) and isinstance(t, type(Union)): # python 3.5 has special consideration for Union
|
if sys.version_info < (3, 7): # nocoverage
|
||||||
origin = Union
|
if origin == List:
|
||||||
else:
|
origin = list
|
||||||
origin = getattr(t, "__origin__", None)
|
elif origin == Dict:
|
||||||
else: # nocoverage # python3.7+
|
origin = dict
|
||||||
origin = getattr(t, "__origin__", None)
|
elif origin == Iterable:
|
||||||
if origin == list:
|
origin = abc.Iterable
|
||||||
origin = List
|
elif origin == Mapping:
|
||||||
elif origin == dict:
|
origin = abc.Mapping
|
||||||
origin = Dict
|
elif origin == Sequence:
|
||||||
elif origin == abc.Iterable:
|
origin = abc.Sequence
|
||||||
origin = Iterable
|
|
||||||
elif origin == abc.Mapping:
|
|
||||||
origin = Mapping
|
|
||||||
elif origin == abc.Sequence:
|
|
||||||
origin = Sequence
|
|
||||||
|
|
||||||
if not origin:
|
if not origin:
|
||||||
# Then it's most likely one of the fundamental data types
|
# Then it's most likely one of the fundamental data types
|
||||||
# I.E. Not one of the data types from the "typing" module.
|
# I.E. Not one of the data types from the "typing" module.
|
||||||
return t
|
return t
|
||||||
elif origin == Union:
|
elif origin == Union:
|
||||||
subtypes = []
|
subtypes = [self.get_standardized_argument_type(st) for st in t.__args__]
|
||||||
if sys.version_info < (3, 6): # nocoverage # in python3.6+
|
|
||||||
args = t.__union_params__
|
|
||||||
else: # nocoverage # in python3.5
|
|
||||||
args = t.__args__
|
|
||||||
for st in args:
|
|
||||||
subtypes.append(self.get_standardized_argument_type(st))
|
|
||||||
return self.get_type_by_priority(subtypes)
|
return self.get_type_by_priority(subtypes)
|
||||||
elif origin in [List, Iterable, Sequence]:
|
elif origin in [list, abc.Iterable, abc.Sequence]:
|
||||||
[st] = t.__args__
|
[st] = t.__args__
|
||||||
return (list, self.get_standardized_argument_type(st))
|
return (list, self.get_standardized_argument_type(st))
|
||||||
elif origin in [Dict, Mapping]:
|
elif origin in [dict, abc.Mapping]:
|
||||||
return dict
|
return dict
|
||||||
raise AssertionError(f"Unknown origin {origin}")
|
raise AssertionError(f"Unknown origin {origin}")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue