diff options
| author | Guido van Rossum <guido@python.org> | 2021-08-16 18:34:23 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-16 18:34:23 (GMT) |
| commit | 62bd97303eb6d1fb0109e4a57d38c2ba6b0be7ff (patch) | |
| tree | 63ac3d6fbe5a343b65d538b86ddd7f2566ab348e /Lib/test/test_code.py | |
| parent | a0a6d39295a30434b088f4b66439bf5ea21a3e4e (diff) | |
| download | cpython-62bd97303eb6d1fb0109e4a57d38c2ba6b0be7ff.zip cpython-62bd97303eb6d1fb0109e4a57d38c2ba6b0be7ff.tar.gz cpython-62bd97303eb6d1fb0109e4a57d38c2ba6b0be7ff.tar.bz2 | |
Fix a SystemError in code.replace() (#27771)
While the comment said 'We don't bother resizing localspluskinds',
this would cause .replace() to crash when it happened.
(Also types.CodeType(), but testing that is tedious, and this tests all
code paths.)
Diffstat (limited to 'Lib/test/test_code.py')
| -rw-r--r-- | Lib/test/test_code.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py index 2bdd7e7..9d6b465 100644 --- a/Lib/test/test_code.py +++ b/Lib/test/test_code.py @@ -320,6 +320,15 @@ class CodeTest(unittest.TestCase): with self.assertRaises(ValueError): co.replace(co_nlocals=co.co_nlocals + 1) + def test_shrinking_localsplus(self): + # Check that PyCode_NewWithPosOnlyArgs resizes both + # localsplusnames and localspluskinds, if an argument is a cell. + def func(arg): + return lambda: arg + code = func.__code__ + newcode = code.replace(co_name="func") # Should not raise SystemError + self.assertEqual(code, newcode) + def test_empty_linetable(self): def func(): pass |
