summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_type_params.py13
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2023-09-13-08-42-45.gh-issue-109219.UiN8sc.rst2
-rw-r--r--Python/symtable.c5
3 files changed, 17 insertions, 3 deletions
diff --git a/Lib/test/test_type_params.py b/Lib/test/test_type_params.py
index b1848ae..25ee188 100644
--- a/Lib/test/test_type_params.py
+++ b/Lib/test/test_type_params.py
@@ -694,6 +694,19 @@ class TypeParamsClassScopeTest(unittest.TestCase):
cls = ns["outer"]()
self.assertEqual(cls.Alias.__value__, "class")
+ def test_nested_free(self):
+ ns = run_code("""
+ def f():
+ T = str
+ class C:
+ T = int
+ class D[U](T):
+ x = T
+ return C
+ """)
+ C = ns["f"]()
+ self.assertIn(int, C.D.__bases__)
+ self.assertIs(C.D.x, str)
class TypeParamsManglingTest(unittest.TestCase):
def test_mangling(self):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-09-13-08-42-45.gh-issue-109219.UiN8sc.rst b/Misc/NEWS.d/next/Core and Builtins/2023-09-13-08-42-45.gh-issue-109219.UiN8sc.rst
new file mode 100644
index 0000000..2c141f0
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2023-09-13-08-42-45.gh-issue-109219.UiN8sc.rst
@@ -0,0 +1,2 @@
+Fix compiling type param scopes that use a name which is also free in an
+inner scope.
diff --git a/Python/symtable.c b/Python/symtable.c
index 691698e..4989e03 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -801,8 +801,7 @@ update_symbols(PyObject *symbols, PyObject *scopes,
the class that has the same name as a local
or global in the class scope.
*/
- if (classflag &&
- PyLong_AS_LONG(v) & (DEF_BOUND | DEF_GLOBAL)) {
+ if (classflag) {
long flags = PyLong_AS_LONG(v) | DEF_FREE_CLASS;
v_new = PyLong_FromLong(flags);
if (!v_new) {
@@ -1037,7 +1036,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
goto error;
/* Records the results of the analysis in the symbol table entry */
if (!update_symbols(ste->ste_symbols, scopes, bound, newfree, inlined_cells,
- ste->ste_type == ClassBlock))
+ (ste->ste_type == ClassBlock) || ste->ste_can_see_class_scope))
goto error;
temp = PyNumber_InPlaceOr(free, newfree);