Conversation
Undecorated subclasses inherited a hash that only captured the base class identity, so frozen subclasses with equal fields collided. Use id(type(self)) so each subclass hashes distinctly.
Merging this PR will degrade performance by 14.66%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | test_hash |
2.7 ms | 3.1 ms | -14.66% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing 00200200:fix-528-hash-instance-type (cfc1c25) with main (65c80d7)2
Footnotes
-
2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
No successful run was found on
main(8f76777) during the generation of this report, so 65c80d7 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
Summary
Generated
__hash__mixed in a class identity captured when the method was created.Undecorated subclasses therefore inherited the base class's hash component and collided for equal field values (#528).
This switches that component to
id(type(self)), so each subclass hashes distinctly while same-class instances keep matching hashes. That matches the hashing docs and Hynek's note on mixing a type identity into the hash.Pull Request Checklist
mainbranch..pyi).typing_tests/baseline.pyor, if necessary,typing_tests/mypy.py.attr/__init__.pyi, they've also been re-imported inattrs/__init__.pyi.docs/api.rstby hand.@attr.s()and@attrs.define()have to be added by hand too.versionadded,versionchanged, ordeprecateddirectives.The next version is the second number in the current release + 1.
The first number represents the current year.
So if the current version on PyPI is 26.2.0, the next version is gonna be 26.3.0.
If the next version is the first in the new year, it'll be 27.1.0.
.rstand.mdfiles is written using semantic newlines.changelog.d.Fixes #528