Issue 44891: Tests for `id(a) == id(a * 1)` for `bytes` and `str`
Issue44891
Created on 2021-08-11 20:01 by sobolevn, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 27745 | merged | sobolevn, 2021-08-12 16:44 | |
| PR 27756 | merged | miss-islington, 2021-08-13 10:36 | |
| Messages (6) | |||
|---|---|---|---|
| msg399414 - (view) | Author: Nikita Sobolev (sobolevn) * ![]() |
Date: 2021-08-11 20:01 | |
While working on `RustPython` (original issue: https://github.com/RustPython/RustPython/issues/2840), I've noticed that `tuple` in CPython has explicit tests that `id` does not change when multiplied by `1`, related: - https://github.com/python/cpython/blob/64a7812c170f5d46ef16a1517afddc7cd92c5240/Lib/test/seq_tests.py#L322 - https://github.com/python/cpython/blob/64a7812c170f5d46ef16a1517afddc7cd92c5240/Lib/test/seq_tests.py#L286-L287 But, I cannot find similar tests for `str` and `bytes` which also have the same behavior: - `str`: https://github.com/python/cpython/blob/64a7812c170f5d46ef16a1517afddc7cd92c5240/Objects/unicodeobject.c#L12709-L12710 - `bytes`: https://github.com/python/cpython/blob/64a7812c170f5d46ef16a1517afddc7cd92c5240/Objects/bytesobject.c#L1456-L1458 Code: ```python >>> 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. |
|||
| msg399484 - (view) | Author: Dennis Sweeney (Dennis Sweeney) * ![]() |
Date: 2021-08-12 22:22 | |
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. |
|||
| msg399514 - (view) | Author: Łukasz Langa (lukasz.langa) * ![]() |
Date: 2021-08-13 10:04 | |
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. |
|||
| msg399518 - (view) | Author: Łukasz Langa (lukasz.langa) * ![]() |
Date: 2021-08-13 10:36 | |
New changeset a2ce538e16d5e3a6168704366bdd7a8c5af29881 by Nikita Sobolev in branch 'main': bpo-44891: Tests `id` preserving on `* 1` for `str` and `bytes` (GH-27745) https://github.com/python/cpython/commit/a2ce538e16d5e3a6168704366bdd7a8c5af29881 |
|||
| msg399523 - (view) | Author: miss-islington (miss-islington) | Date: 2021-08-13 11:04 | |
New changeset 45a97d91a42795fb0b220e67ee25a14b940c7e50 by Miss Islington (bot) in branch '3.10': bpo-44891: Tests `id` preserving on `* 1` for `str` and `bytes` (GH-27745) https://github.com/python/cpython/commit/45a97d91a42795fb0b220e67ee25a14b940c7e50 |
|||
| msg399524 - (view) | Author: Łukasz Langa (lukasz.langa) * ![]() |
Date: 2021-08-13 11:06 | |
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! ✨ 🍰 ✨ |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:48 | admin | set | github: 89054 |
| 2021-08-13 11:06:03 | lukasz.langa | set | status: open -> closed resolution: fixed messages: + msg399524 stage: patch review -> resolved |
| 2021-08-13 11:04:12 | miss-islington | set | messages: + msg399523 |
| 2021-08-13 10:36:36 | lukasz.langa | set | messages: + msg399518 |
| 2021-08-13 10:36:30 | miss-islington | set | nosy:
+ miss-islington pull_requests: + pull_request26232 |
| 2021-08-13 10:04:18 | lukasz.langa | set | nosy:
+ lukasz.langa messages: + msg399514 |
| 2021-08-12 22:22:23 | Dennis Sweeney | set | nosy:
+ Dennis Sweeney messages: + msg399484 |
| 2021-08-12 16:44:38 | sobolevn | set | keywords:
+ patch stage: patch review pull_requests: + pull_request26223 |
| 2021-08-11 20:01:19 | sobolevn | create | |

