-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Tests for id(a) == id(a * 1)
for bytes
and str
#89054
Comments
While working on
But, I cannot find similar tests for
Code: >>> b = b'abc'
>>> id(b), id(b * 1), id(b) == id(b * 1)
(4491073360, 4491073360, True)
>>> s = 'abc'
>>> id(s), id(s * 1), id(s) == id(s * 1)
(4489513776, 4489513776, True) If tests are indeed missing and should be added, I would love to contribute them. |
Perhaps it would be better to convert existing such tests to @cpython_only, since as far as I know, id() and |
Dennis, there's an existing issue on making the test suite more pypy-compatible: https://bugs.python.org/issue25130 In that issue Maciej says pypy adopted a policy to adjust tests when they have to so I'd say that unless we get a report on which additional tests should be marked as cpython_only, I wouldn't proactively do it myself. In fact, a RustPython core dev is specifically asking for more tests here so I don't see why we shouldn't accommodate that. |
I opted for landing this and backporting to 3.10 to increase visibility. There will be a NEWS entry about this so if any alt implementations have issues with this test, they can reach us and we'll adapt. Thanks, Nikita! ✨ 🍰 ✨ |
Why don't subclasses of str and bytes preserve this property? Is that a missed optimization? |
Subclasses might be mutable: >>> class S(str):
... def __init__(self, *args, **kwargs):
... super().__init__(*args, **kwargs)
... self.mutable = []
...
>>> s = S()
>>> s.mutable.append(1) They might also change how multiplication works. |
Makes sense, thanks. I just now added a test and fix for
|
id
preserving on* 1
forstr
andbytes
#27745id
preserving on* 1
forstr
andbytes
(GH-27745) #27756Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: