8000 gh-104549: Set __module__ on TypeAliasType by JelleZijlstra · Pull Request #104550 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-104549: Set __module__ on TypeAliasType #104550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 18, 2023
Prev Previous commit
Next Next commit
Add pickling tests, fix refcounting bug
  • Loading branch information
JelleZijlstra committed May 18, 2023
commit 90a846c7a529623756178ae807dd1a8c9b92f0d0
7 changes: 7 additions & 0 deletions Lib/test/test_type_aliases.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pickle
import types
import unittest
from test.support import check_syntax_error, run_code
Expand Down Expand Up @@ -214,3 +215,9 @@ def test_module(self):
mod_generics_cache.__name__)
self.assertEqual(mod_generics_cache.OldStyle.__module__,
mod_generics_cache.__name__)

def test_pickling(self):
pickled = pickle.dumps(mod_generics_cache.Alias)
self.assertIs(pickle.loads(pickled), mod_generics_cache.Alias)
pickled = pickle.dumps(mod_generics_cache.OldStyle)
self.assertIs(pickle.loads(pickled), mod_generics_cache.OldStyle)
3 changes: 2 additions & 1 deletion Objects/typevarobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,8 @@ typealias_module(PyObject *self, void *unused)
return Py_NewRef(ta->module);
}
if (ta->compute_value != NULL) {
return PyFunction_GetModule(ta->compute_value);
// PyFunction_GetModule() returns a borrowed reference
return Py_NewRef(PyFunction_GetModule(ta->compute_value));
}
Py_RETURN_NONE;
}
Expand Down
0