@@ -1333,10 +1333,10 @@ def __init__(self, name, type_var, impl_type, type_checker):
1333
1333
assert isinstance (type_var , type ), repr (type_var )
1334
1334
assert isinstance (impl_type , type ), repr (impl_type )
1335
1335
assert not isinstance (impl_type , TypingMeta ), repr (impl_type )
1336
- self .name = name # The name, e.g. 'Pattern'
1337
- self .type_var = type_var # The type parameter, e.g. 'AnyStr', or the specific type, e.g. 'str'
1338
- self .impl_type = impl_type # The implementation type
1339
- self .type_checker = type_checker # Function that takes an impl_type instance and returns a value that should be a type_var instance
1336
+ self .name = name
1337
+ self .type_var = type_var
1338
+ self .impl_type = impl_type
1339
+ self .type_checker = type_checker
1340
1340
1341
1341
def __repr__ (self ):
1342
1342
return "%s[%s]" % (self .name , _type_repr (self .type_var ))
@@ -1346,22 +1346,28 @@ def __getitem__(self, parameter):
1346
1346
if not isinstance (self .type_var , TypeVar ):
1347
1347
raise TypeError ("%s cannot be further parameterized." % self )
1348
1348
if not issubclass (parameter , self .type_var ):
1349
- raise TypeError ("%s is not a valid substitution for %s." % (parameter , self .type_var ))
1350
- return self .__class__ (self .name , parameter , self .impl_type , self .type_checker )
1349
+ raise TypeError ("%s is not a valid substitution for %s." %
1350
+ (parameter , self .type_var ))
1351
+ return self .__class__ (self .name , parameter ,
1352
+ self .impl_type , self .type_checker )
1351
1353
1352
1354
def __instancecheck__ (self , obj ):
1353
- return isinstance (obj , self .impl_type ) and isinstance (self .type_checker (obj ), self .type_var )
1355
+ return (isinstance (obj , self .impl_type ) and
1356
+ isinstance (self .type_checker (obj ), self .type_var ))
1354
1357
1355
1358
def __subclasscheck__ (self , cls ):
1356
1359
if isinstance (cls , _TypeAlias ):
1357
1360
# Covariance. For now, we compare by name.
1358
- return (cls .name == self .name and issubclass (cls .type_var , self .type_var ))
1361
+ return (cls .name == self .name and
1362
+ issubclass (cls .type_var , self .type_var ))
1359
1363
else :
1360
1364
# Note that this is too lenient, because the
1361
1365
# implementation type doesn't carry information about
1362
1366
# whether it is about bytes or str (for example).
1363
1367
return issubclass (cls , self .impl_type )
1364
1368
1365
1369
1366
- Pattern = _TypeAlias ('Pattern' , AnyStr , type (re .compile ('' )), lambda p : p .pattern )
1367
- Match = _TypeAlias ('Match' , AnyStr , type (re .match ('' , '' )), lambda m : m .re .pattern )
1370
+ Pattern = _TypeAlias ('Pattern' , AnyStr , type (re .compile ('' )),
1371
+ lambda p : p .pattern )
1372
+ Match = _TypeAlias ('Match' , AnyStr , type (re .match ('' , '' )),
1373
+ lambda m : m .re .pattern )
0 commit comments