You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tests for id(a) == id(a * 1) for bytes and str #89054
Note: 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:
assignee=Noneclosed_at=<Date2021-08-13.11:06:03.632>created_at=<Date2021-08-11.20:01:19.832>labels= ['type-feature', 'tests']
title='Tests for `id(a) == id(a * 1)` for `bytes` and `str`'updated_at=<Date2021-08-13.11:06:03.631>user='https://github.com/sobolevn'
While working on RustPython (original issue: RustPython/RustPython#2840), I've noticed that tuple in CPython has explicit tests that id does not change when multiplied by 1, related:
Perhaps it would be better to convert existing such tests to @cpython_only, since as far as I know, id() and is are implementation-defined for immutable objects.
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.
Activity
sobolevn commentedon Aug 11, 2021
While working on
RustPython(original issue: RustPython/RustPython#2840), I've noticed thattuplein CPython has explicit tests thatiddoes not change when multiplied by1, related:cpython/Lib/test/seq_tests.py
Line 322 in 64a7812
cpython/Lib/test/seq_tests.py
Lines 286 to 287 in 64a7812
But, I cannot find similar tests for
strandbyteswhich also have the same behavior:str:cpython/Objects/unicodeobject.c
Lines 12709 to 12710 in 64a7812
bytes:cpython/Objects/bytesobject.c
Lines 1456 to 1458 in 64a7812
Code:
If tests are indeed missing and should be added, I would love to contribute them.
sweeneyde commentedon Aug 12, 2021
Perhaps it would be better to convert existing such tests to @cpython_only, since as far as I know, id() and
isare implementation-defined for immutable objects.ambv commentedon Aug 13, 2021
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.
ambv commentedon Aug 13, 2021
New changeset a2ce538 by Nikita Sobolev in branch 'main':
bpo-44891: Tests
idpreserving on* 1forstrandbytes(GH-27745)a2ce538
miss-islington commentedon Aug 13, 2021
New changeset 45a97d9 by Miss Islington (bot) in branch '3.10':
bpo-44891: Tests
idpreserving on* 1forstrandbytes(GH-27745)45a97d9
ambv commentedon Aug 13, 2021
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! ✨ 🍰 ✨
mattip commentedon Feb 14, 2023
Why don't subclasses of str and bytes preserve this property? Is that a missed optimization?
sobolevn commentedon Feb 14, 2023
Subclasses might be mutable:
They might also change how multiplication works.
mattip commentedon Feb 14, 2023
Makes sense, thanks. I just now added a test and fix for
a * 1for PyPy. I think I should also make PyPy respect addition: