bpo-28556: Minor fixes for typing module (GH-6732) · python/cpython@43d12a6 (original) (raw)
`@@ -1324,6 +1324,72 @@ class D(C):
`
1324
1324
`with self.assertRaises(Exception):
`
1325
1325
`D[T]
`
1326
1326
``
``
1327
`+
def test_new_with_args(self):
`
``
1328
+
``
1329
`+
class A(Generic[T]):
`
``
1330
`+
pass
`
``
1331
+
``
1332
`+
class B:
`
``
1333
`+
def new(cls, arg):
`
``
1334
`+
call object
`
``
1335
`+
obj = super().new(cls)
`
``
1336
`+
obj.arg = arg
`
``
1337
`+
return obj
`
``
1338
+
``
1339
`+
mro: C, A, Generic, B, object
`
``
1340
`+
class C(A, B):
`
``
1341
`+
pass
`
``
1342
+
``
1343
`+
c = C('foo')
`
``
1344
`+
self.assertEqual(c.arg, 'foo')
`
``
1345
+
``
1346
`+
def test_new_with_args2(self):
`
``
1347
+
``
1348
`+
class A:
`
``
1349
`+
def init(self, arg):
`
``
1350
`+
self.from_a = arg
`
``
1351
`+
call object
`
``
1352
`+
super().init()
`
``
1353
+
``
1354
`+
mro: C, Generic, A, object
`
``
1355
`+
class C(Generic[T], A):
`
``
1356
`+
def init(self, arg):
`
``
1357
`+
self.from_c = arg
`
``
1358
`+
call Generic
`
``
1359
`+
super().init(arg)
`
``
1360
+
``
1361
`+
c = C('foo')
`
``
1362
`+
self.assertEqual(c.from_a, 'foo')
`
``
1363
`+
self.assertEqual(c.from_c, 'foo')
`
``
1364
+
``
1365
`+
def test_new_no_args(self):
`
``
1366
+
``
1367
`+
class A(Generic[T]):
`
``
1368
`+
pass
`
``
1369
+
``
1370
`+
class B:
`
``
1371
`+
def new(cls):
`
``
1372
`+
call object
`
``
1373
`+
obj = super().new(cls)
`
``
1374
`+
obj.from_b = 'b'
`
``
1375
`+
return obj
`
``
1376
+
``
1377
`+
mro: C, A, Generic, B, object
`
``
1378
`+
class C(A, B):
`
``
1379
`+
def init(self, arg):
`
``
1380
`+
self.arg = arg
`
``
1381
+
``
1382
`+
def new(cls, arg):
`
``
1383
`+
call A
`
``
1384
`+
obj = super().new(cls)
`
``
1385
`+
obj.from_c = 'c'
`
``
1386
`+
return obj
`
``
1387
+
``
1388
`+
c = C('foo')
`
``
1389
`+
self.assertEqual(c.arg, 'foo')
`
``
1390
`+
self.assertEqual(c.from_b, 'b')
`
``
1391
`+
self.assertEqual(c.from_c, 'c')
`
``
1392
+
1327
1393
``
1328
1394
`class ClassVarTests(BaseTestCase):
`
1329
1395
``
`@@ -1737,6 +1803,8 @@ def test_get_type_hints_classes(self):
`
1737
1803
`self.assertEqual(gth(HasForeignBaseClass),
`
1738
1804
` {'some_xrepr': XRepr, 'other_a': mod_generics_cache.A,
`
1739
1805
`'some_b': mod_generics_cache.B})
`
``
1806
`+
self.assertEqual(gth(XRepr.new),
`
``
1807
`+
{'x': int, 'y': int})
`
1740
1808
`self.assertEqual(gth(mod_generics_cache.B),
`
1741
1809
` {'my_inner_a1': mod_generics_cache.B.A,
`
1742
1810
`'my_inner_a2': mod_generics_cache.B.A,
`