forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpo-42266: Handle monkey-patching descriptors in LOAD_ATTR cache (pyt…
- Loading branch information
Showing
4 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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,23 @@ | ||
import unittest | ||
|
||
class TestLoadAttrCache(unittest.TestCase): | ||
def test_descriptor_added_after_optimization(self): | ||
class Descriptor: | ||
pass | ||
|
||
class C: | ||
def __init__(self): | ||
self.x = 1 | ||
x = Descriptor() | ||
|
||
def f(o): | ||
return o.x | ||
|
||
o = C() | ||
for i in range(1025): | ||
assert f(o) == 1 | ||
|
||
Descriptor.__get__ = lambda self, instance, value: 2 | ||
Descriptor.__set__ = lambda *args: None | ||
|
||
self.assertEqual(f(o), 2) |
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Core and Builtins/2020-11-04-23-03-25.bpo-42266.G4hGDe.rst
This file contains 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,3 @@ | ||
Fixed a bug with the LOAD_ATTR opcode cache that was not respecting | ||
monkey-patching a class-level attribute to make it a descriptor. Patch by | ||
Pablo Galindo. |
This file contains 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
This file contains 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