@@ -1407,6 +1407,11 @@ def _get_defaults(func):
1407
1407
return res
1408
1408
1409
1409
1410
+ _allowed_types = (types .FunctionType , types .BuiltinFunctionType ,
1411
+ types .MethodType , types .ModuleType ,
1412
+ SlotWrapperType , MethodWrapperType , MethodDescriptorType )
1413
+
1414
+
1410
1415
def get_type_hints (obj , globalns = None , localns = None ):
1411
1416
"""Return type hints for an object.
1412
1417
@@ -1461,15 +1466,7 @@ def get_type_hints(obj, globalns=None, localns=None):
1461
1466
hints = getattr (obj , '__annotations__' , None )
1462
1467
if hints is None :
1463
1468
# 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 ):
1473
1470
return {}
1474
1471
else :
1475
1472
raise TypeError ('{!r} is not a module, class, method, '
0 commit comments