Skip to content

Commit 2d85d8c

Browse files
authored
Compactify get_type_hints code (#388)
1 parent 440dcde commit 2d85d8c

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/typing.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,11 @@ def _get_defaults(func):
14071407
return res
14081408

14091409

1410+
_allowed_types = (types.FunctionType, types.BuiltinFunctionType,
1411+
types.MethodType, types.ModuleType,
1412+
SlotWrapperType, MethodWrapperType, MethodDescriptorType)
1413+
1414+
14101415
def get_type_hints(obj, globalns=None, localns=None):
14111416
"""Return type hints for an object.
14121417
@@ -1461,15 +1466,7 @@ def get_type_hints(obj, globalns=None, localns=None):
14611466
hints = getattr(obj, '__annotations__', None)
14621467
if hints is None:
14631468
# Return empty annotations for something that _could_ have them.
1464-
if (
1465-
isinstance(obj, types.FunctionType) or
1466-
isinstance(obj, types.BuiltinFunctionType) or
1467-
isinstance(obj, types.MethodType) or
1468-
isinstance(obj, types.ModuleType) or
1469-
isinstance(obj, SlotWrapperType) or
1470-
isinstance(obj, MethodWrapperType) or
1471-
isinstance(obj, MethodDescriptorType)
1472-
):
1469+
if isinstance(obj, _allowed_types):
14731470
return {}
14741471
else:
14751472
raise TypeError('{!r} is not a module, class, method, '

0 commit comments

Comments
 (0)