Skip to content

Commit 66ac040

Browse files
committed
requested changes
1 parent 840023e commit 66ac040

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

Lib/test/test_type_params.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,15 +1184,14 @@ def func2[X, Y](x: X | Y) -> X | Y: ...
11841184
def func3[X, *Y, **Z](x: X, y: tuple[*Y], z: Z) -> X: ...
11851185
def func4[X: int, Y: (bytes, str)](x: X, y: Y) -> X | Y: ...
11861186
def func3b[X, *Y, **Z]() -> X: return Class3[X, Y, Z]()
1187-
def func5[Baz](): return Class5[Baz]()
1187+
def func5[Baz](): return Class1[Baz]()
11881188

11891189
class Class1[X]: ...
11901190
class Class2[X, Y]: ...
11911191
class Class3[X, *Y, **Z]: ...
11921192
class Class4[X: int, Y: (bytes, str)]: ...
1193-
class Class5(Generic[T]): pass
1194-
class Class6:
1195-
def meth[Baz](): return Class5[Baz]()
1193+
class Class5:
1194+
def meth[Baz](): return Class1[Baz]()
11961195

11971196

11981197
class TypeParamsPickleTest(unittest.TestCase):
@@ -1271,12 +1270,12 @@ def test_pickling_anonymous_typeparams(self):
12711270
unpickled = pickle.loads(pickled)
12721271
self.assertIs(unpickled, thing)
12731272

1274-
thing = Class6.meth()
1273+
thing = Class5.meth()
12751274
pickled = pickle.dumps(thing)
12761275
unpickled = pickle.loads(pickled)
12771276
self.assertIs(unpickled.__orig_class__, thing.__orig_class__)
12781277
self.assertIs(unpickled.__orig_class__.__args__[0],
1279-
Class6.meth.__type_params__[0])
1278+
Class5.meth.__type_params__[0])
12801279

12811280

12821281
class TypeParamsWeakRefTest(unittest.TestCase):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Allow pickle of instances of generic classes.
1+
Fix pickling of generic classes instances.

Modules/_typingmodule.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,13 @@ _typing__restore_anonymous_typeparam_impl(PyObject *module, PyObject *owner,
4949
PyObject *index)
5050
/*[clinic end generated code: output=00baec27dbf8d2d9 input=2f048db28d8124fb]*/
5151
{
52-
PyObject *ret = NULL;
5352
PyObject *type_params = PyObject_GetAttr(owner, &_Py_ID(__type_params__));
54-
5553
if (type_params == NULL) {
56-
goto done;
54+
return NULL;
5755
}
58-
59-
ret = PyObject_GetItem(type_params, index);
60-
61-
done:
62-
Py_XDECREF(type_params);
63-
return ret;
56+
PyObject *res = PyObject_GetItem(type_params, index);
57+
Py_DECREF(type_params);
58+
return res;
6459
}
6560

6661

0 commit comments

Comments
 (0)