FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-159739: Do not intern complex subclasses in code constants (GH-159980) by miss-islington · Pull Request #160250 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 6 additions & 1 deletion Lib/test/test_code.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1245,10 +1245,15 @@ def __hash__(self):
class MyInt(int):
pass

class MyComplex(complex):
pass

code = compile("a = 1", "<string>", "exec")
code = code.replace(co_consts=(1, Unhashable(), MyInt(1), MyInt(1)))
code = code.replace(co_consts=(1, Unhashable(), MyInt(1), MyInt(1),
MyComplex(1j)))
self.assertIsInstance(code.co_consts[1], Unhashable)
self.assertEqual(code.co_consts[2], code.co_consts[3])
self.assertFalse(sys._is_immortal(code.co_consts[4]))


class CodeWeakRefTest(unittest.TestCase):
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Prevent free-threaded builds from interning and immortalizing complex
subclasses in code object constants.
2 changes: 1 addition & 1 deletion Objects/codeobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ should_immortalize_constant(PyObject *v)
_Py_IsImmortal(slice->step));
}
return (PyLong_CheckExact(v) || PyFloat_CheckExact(v) ||
PyComplex_Check(v) || PyBytes_CheckExact(v));
PyComplex_CheckExact(v) || PyBytes_CheckExact(v));
}
#endif

Expand Down
Loading

Back | FazBrowse Home | New Git URL