Fix ClassVar forward reference detection - #1593
Conversation
d1d8e8d to
c74040f
Compare
Merging this PR will degrade performance by 61.12%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | WallTime | import attrs |
49.2 ms | 127 ms | -61.28% |
| ❌ | WallTime | import attr |
48.7 ms | 124.9 ms | -60.96% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing wanxiankai:fix/classvar-forwardref (8328ba7) with main (c27ba27)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(ca0f045) during the generation of this report, so c27ba27 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
Summary
Fixes #1575.
_is_class_var()now unwrapsForwardRef.__forward_arg__before applying the existing string-prefix checks.This lets
attrsrecognize Python 3.14-style forward references such asForwardRef("ClassVar[str]", is_class=True)as class variables whenClassVarwas only imported underTYPE_CHECKING.Tests cover both the direct
_is_class_var()case and the Python 3.14attrs.definebehavior from the issue.Pull Request Checklist
mainbranch..pyi).typing-examples/baseline.pyor, if necessary,typing-examples/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.