summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_scope.py24
-rw-r--r--Objects/codeobject.c2
2 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py
index 6e46dfa..24a366e 100644
--- a/Lib/test/test_scope.py
+++ b/Lib/test/test_scope.py
@@ -810,6 +810,30 @@ class ScopeTests(unittest.TestCase):
gc_collect() # For PyPy or other GCs.
self.assertIsNone(ref())
+ def test_multiple_nesting(self):
+ # Regression test for https://github.com/python/cpython/issues/121863
+ class MultiplyNested:
+ def f1(self):
+ __arg = 1
+ class D:
+ def g(self, __arg):
+ return __arg
+ return D().g(_MultiplyNested__arg=2)
+
+ def f2(self):
+ __arg = 1
+ class D:
+ def g(self, __arg):
+ return __arg
+ return D().g
+
+ inst = MultiplyNested()
+ with self.assertRaises(TypeError):
+ inst.f1()
+
+ closure = inst.f2()
+ with self.assertRaises(TypeError):
+ closure(_MultiplyNested__arg=2)
if __name__ == '__main__':
unittest.main()
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 7493280..d45ba5e 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -147,7 +147,7 @@ intern_strings(PyObject *tuple)
"non-string found in code slot");
return -1;
}
- _PyUnicode_InternMortal(interp, &_PyTuple_ITEMS(tuple)[i]);
+ _PyUnicode_InternImmortal(interp, &_PyTuple_ITEMS(tuple)[i]);
}
return 0;
}