7
7
import re as stdlib_re # Avoid confusion with the re we export.
8
8
import sys
9
9
import types
10
+ import copy
10
11
try :
11
12
import collections .abc as collections_abc
12
13
except ImportError :
@@ -1253,11 +1254,6 @@ def __instancecheck__(self, instance):
1253
1254
return issubclass (instance .__class__ , self )
1254
1255
return False
1255
1256
1256
- def __copy__ (self ):
1257
- return self .__class__ (self .__name__ , self .__bases__ , dict (self .__dict__ ),
1258
- self .__parameters__ , self .__args__ , self .__origin__ ,
1259
- self .__extra__ , self .__orig_bases__ )
1260
-
1261
1257
def __setattr__ (self , attr , value ):
1262
1258
# We consider all the subscripted genrics as proxies for original class
1263
1259
if (
@@ -1269,6 +1265,16 @@ def __setattr__(self, attr, value):
1269
1265
super (GenericMeta , self ._gorg ).__setattr__ (attr , value )
1270
1266
1271
1267
1268
+ def _copy_generic (self ):
1269
+ """Hack to work around https://bugs.python.org/issue11480 on Python 2"""
1270
+ return self .__class__ (self .__name__ , self .__bases__ , dict (self .__dict__ ),
1271
+ self .__parameters__ , self .__args__ , self .__origin__ ,
1272
+ self .__extra__ , self .__orig_bases__ )
1273
+
1274
+
1275
+ copy ._copy_dispatch [GenericMeta ] = _copy_generic
1276
+
1277
+
1272
1278
# Prevent checks for Generic to crash when defining Generic.
1273
1279
Generic = None
1274
1280
@@ -1365,6 +1371,9 @@ def __subclasscheck__(self, cls):
1365
1371
"with issubclass()." )
1366
1372
1367
1373
1374
+ copy ._copy_dispatch [TupleMeta ] = _copy_generic
1375
+
1376
+
1368
1377
class Tuple (tuple ):
1369
1378
"""Tuple type; Tuple[X, Y] is the cross-product type of X and Y.
1370
1379
@@ -1443,6 +1452,9 @@ def __getitem_inner__(self, parameters):
1443
1452
return super (CallableMeta , self ).__getitem__ (parameters )
1444
1453
1445
1454
1455
+ copy ._copy_dispatch [CallableMeta ] = _copy_generic
1456
+
1457
+
1446
1458
class Callable (object ):
1447
1459
"""Callable type; Callable[[int], str] is a function of (int) -> str.
1448
1460
0 commit comments