Conversation
Review CompleteYour review story is ready! Comment !reviewfast on this PR to re-generate the story. |
|
What happens to: assert id([]) == id({})
# or even
assert id([]) == id((1,))Is there a possibility that the same slot could get reused causing the same id for different values? I guess the same could be true for cpython. I guess the one case we want to avoid is where python says |
|
It's documented https://docs.python.org/3/library/functions.html#id
... which is the case for all these tests. Whether they actually do is an implementation detail. I feel that it's more correct to not leak than to attempt to match CPython implementation details here. |
|
Small tuple optimization in #90 |
|
okay, I'm good with this change. But let's add those cases I asked about to tests with an explanation to make the behaviour explicit. |
| # === Tuple singleton is guaranteed to have a unique id === | ||
| assert id([]) != id(()), 'list vs tuple singleton distinct' | ||
| assert id({}) != id(()), 'dict vs tuple singleton distinct' | ||
| assert id(1) != id(()), 'int vs tuple singleton distinct' |
There was a problem hiding this comment.
These cases will fail until #90 is merged.
The justification in
idto leak seems completely baseless, as CPython indeed returnsTruein the case mentioned in the comment:There is one test failure, for
id([]) != id(()), the way to solve this IMO would be to make()a singleton like it is in CPython (which would be a performance win anyway).