-
Notifications
You must be signed in to change notification settings - Fork 19
jit-trace, _weakref: gate the class-attribute fold on a fold census, and reject repr with a foreign self #1471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
755b9a3
weakref: reject repr calls with a foreign self
youknowone 7e5b4da
collections: complete deque repeat and slot storage
youknowone 5245123
complex: preserve exact __complex__ identity
youknowone bba6352
typedef: complete common builtin type surface
youknowone fd588dd
frame: preserve cell arguments captured by closures
youknowone 7163232
pickle: reject unreconstructable native builtin state
youknowone 9d38d1f
set: dispatch subclass repr overrides
youknowone 48b7c45
exceptions: port PyPy constructor args and layout graph
youknowone 43e0a33
docs: pin PyPy module surface boundary
youknowone 24eb2ad
str: port PyPy typed eq_w shortcut
youknowone ce93c5e
__pypy__: port container strategy diagnostics
youknowone 7b83ed9
pickle: exempt a native layout that publishes __getstate__
youknowone 8b39043
extra_tests: gate the __getstate__ pickle boundary snippet
youknowone dbfda53
gc: normalize forwarded roots at host call boundaries
youknowone d54c3f0
list: port PyPy bytes strategy
youknowone 74ec441
bytesobject: write barrier the wrapper w_bytes_from_block builds
youknowone 527282d
list: reserve bytes_items room through the list, not from BytesArray
youknowone 80b3b8f
_pickle: keep the memo and stack lists on the Object strategy
youknowone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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,74 @@ | ||
| # pyre-check: gate=1 | ||
| # `object_getstate` calls an overriding `__getstate__` and only falls back to | ||
| # `object_getstate_default(required)` when the type still uses | ||
| # `object.__getstate__`. The `required` refusal therefore stops at the | ||
| # boundary that hook draws: a native layout publishing one is rebuilt from the | ||
| # state it returns, and one that publishes none cannot be rebuilt through an | ||
| # empty `__newobj__` call. | ||
| # | ||
| # `__reduce_ex__` is called directly rather than through `pickle`: this | ||
| # directory carries its own `_pickle.py`, which shadows the stdlib extension | ||
| # module and stops `import pickle` from working here. That keeps this file | ||
| # green under CPython too, unlike its `pickle_*` neighbours, which is what | ||
| # lets it be gated. | ||
| import io | ||
| import itertools | ||
| import types | ||
|
|
||
|
|
||
| def refuses(obj): | ||
| try: | ||
| obj.__reduce_ex__(2) | ||
| except TypeError as e: | ||
| assert "cannot pickle" in str(e), (obj, str(e)) | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| # --- publishes `__getstate__`: reduces through the hook --------------------- | ||
| b = io.BytesIO(b"abcdef") | ||
| b.seek(2) | ||
| b.tag = "kept" | ||
| assert io.BytesIO.__getstate__ is not object.__getstate__ | ||
| newobj, args, state, listitems, dictitems = b.__reduce_ex__(2) | ||
| assert args == (io.BytesIO,), args | ||
| assert state == (b"abcdef", 2, {"tag": "kept"}), state | ||
| assert listitems is None and dictitems is None, (listitems, dictitems) | ||
|
|
||
| s = io.StringIO("hello") | ||
| s.read(2) | ||
| assert io.StringIO.__getstate__ is not object.__getstate__ | ||
| state = s.__reduce_ex__(2)[2] | ||
| # `(value, readnl, pos, dict)`; the trailing dict is empty here and pyre and | ||
| # CPython spell an empty one differently, so only value and pos are pinned. | ||
| assert state[0] == "hello", state | ||
| assert state[2] == 2, state | ||
|
|
||
| # --- publishes a refusing `__getstate__`: the hook owns the refusal --------- | ||
| w = io.BufferedWriter(io.BytesIO()) | ||
| assert io.BufferedWriter.__getstate__ is not object.__getstate__ | ||
| assert refuses(w) | ||
|
|
||
| # --- publishes none: `object_getstate_default(required)` refuses ------------ | ||
| for obj in ( | ||
| types.ModuleType("m"), | ||
| property(), | ||
| staticmethod(len), | ||
| classmethod(len), | ||
| itertools.count(), | ||
| ): | ||
| assert type(obj).__getstate__ is object.__getstate__, obj | ||
| assert refuses(obj), obj | ||
|
|
||
|
|
||
| # The refusal reaches neither an ordinary instance nor a list or a dict. | ||
| class C: | ||
| def __init__(self): | ||
| self.x = 1 | ||
|
|
||
|
|
||
| assert C().__reduce_ex__(2)[2] == {"x": 1} | ||
| assert list(([1, 2]).__reduce_ex__(2)[3]) == [1, 2] | ||
| assert list(({"a": 1}).__reduce_ex__(2)[4]) == [("a", 1)] | ||
|
|
||
| print("pickle_native_getstate OK") |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Reconcile the hard stop with the explicit-scope exception.
Line 8 permits a user to expand the scope when PyPy has no import or owner. Lines 13-14 prohibit that case without exception. State the exception in the hard-stop rule, or remove it from Line 8, so contributors receive one actionable policy.
Proposed wording
📝 Committable suggestion
🤖 Prompt for AI Agents