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
In the following code, from __future__ import annotations causes the KW_ONLY to become a string.
The dataclasses module can deal with that, but only if the object isn’t in a if TYPE_CHECKING block.
Ruff supports this for things like ClassVar¹, i.e. if a ClassVar is used in a dataclass, Ruff knows the from typing import ClassVar needs to come out of the if TYPE_CHECKING block. However the same doesn’t seem to be true here.
from __future__ importannotationsfromdataclassesimportKW_ONLY, dataclass@dataclassclassTest:
a: int_: KW_ONLYb: str
¹This is probably the place that should handle KW_ONLY
because that way I can use new typing features without having to pay attention that they are imported from typing_extensions or in a if TYPE_CHECKING block for backwards compatibility. They just always are in there.
Seen in Ruff 0.5.7
In the following code,
from __future__ import annotations
causes theKW_ONLY
to become a string.The dataclasses module can deal with that, but only if the object isn’t in a
if TYPE_CHECKING
block.Ruff supports this for things like
ClassVar
¹, i.e. if aClassVar
is used in a dataclass, Ruff knows thefrom typing import ClassVar
needs to come out of theif TYPE_CHECKING
block. However the same doesn’t seem to be true here.¹This is probably the place that should handle KW_ONLY
ruff/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs
Lines 108 to 139 in 82a3e69
The text was updated successfully, but these errors were encountered: