@@ -355,13 +355,17 @@ def _type_check(arg, msg):
355
355
return type (None )
356
356
if isinstance (arg , str ):
357
357
arg = _ForwardRef (arg )
358
- if (isinstance (arg , _TypingBase ) and type (arg ).__name__ == '_ClassVar' or
359
- not isinstance (arg , (type , _TypingBase )) and not callable (arg )):
358
+ if (
359
+ isinstance (arg , _TypingBase ) and type (arg ).__name__ == '_ClassVar' or
360
+ not isinstance (arg , (type , _TypingBase )) and not callable (arg )
361
+ ):
360
362
raise TypeError (msg + " Got %.100r." % (arg ,))
361
363
# Bare Union etc. are not valid as type arguments
362
- if (type (arg ).__name__ in ('_Union' , '_Optional' )
363
- and not getattr (arg , '__origin__' , None )
364
- or isinstance (arg , TypingMeta ) and _gorg (arg ) in (Generic , _Protocol )):
364
+ if (
365
+ type (arg ).__name__ in ('_Union' , '_Optional' ) and
366
+ not getattr (arg , '__origin__' , None ) or
367
+ isinstance (arg , TypingMeta ) and _gorg (arg ) in (Generic , _Protocol )
368
+ ):
365
369
raise TypeError ("Plain %s is not valid as type argument" % arg )
366
370
return arg
367
371
@@ -850,8 +854,10 @@ def _valid_for_check(cls):
850
854
if cls is Generic :
851
855
raise TypeError ("Class %r cannot be used with class "
852
856
"or instance checks" % cls )
853
- if (cls .__origin__ is not None and
854
- sys ._getframe (3 ).f_globals ['__name__' ] not in ['abc' , 'functools' ]):
857
+ if (
858
+ cls .__origin__ is not None and
859
+ sys ._getframe (3 ).f_globals ['__name__' ] not in ['abc' , 'functools' ]
860
+ ):
855
861
raise TypeError ("Parameterized generics cannot be used with class "
856
862
"or instance checks" )
857
863
@@ -987,9 +993,12 @@ def __new__(cls, name, bases, namespace,
987
993
# This allows unparameterized generic collections to be used
988
994
# with issubclass() and isinstance() in the same way as their
989
995
# collections.abc counterparts (e.g., isinstance([], Iterable)).
990
- if ('__subclasshook__' not in namespace and extra # allow overriding
991
- or hasattr (self .__subclasshook__ , '__name__' ) and
992
- self .__subclasshook__ .__name__ == '__extrahook__' ):
996
+ if (
997
+ # allow overriding
998
+ '__subclasshook__' not in namespace and extra or
999
+ hasattr (self .__subclasshook__ , '__name__' ) and
1000
+ self .__subclasshook__ .__name__ == '__extrahook__'
1001
+ ):
993
1002
self .__subclasshook__ = _make_subclasshook (self )
994
1003
if isinstance (extra , abc .ABCMeta ):
995
1004
self ._abc_registry = extra ._abc_registry
@@ -1443,10 +1452,12 @@ def get_type_hints(obj, globalns=None, localns=None):
1443
1452
hints = getattr (obj , '__annotations__' , None )
1444
1453
if hints is None :
1445
1454
# Return empty annotations for something that _could_ have them.
1446
- if (isinstance (obj , types .FunctionType ) or
1455
+ if (
1456
+ isinstance (obj , types .FunctionType ) or
1447
1457
isinstance (obj , types .BuiltinFunctionType ) or
1448
1458
isinstance (obj , types .MethodType ) or
1449
- isinstance (obj , types .ModuleType )):
1459
+ isinstance (obj , types .ModuleType )
1460
+ ):
1450
1461
return {}
1451
1462
else :
1452
1463
raise TypeError ('{!r} is not a module, class, method, '
0 commit comments