mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
RUF009 should behave similar to B008 and ignore attributes with immutable types (#16048)
This PR resolved #15772 Before PR: ``` def _( this_is_fine: int = f(), # No error this_is_not: list[int] = f() # B008: Do not perform function call `f` in argument defaults ): ... @dataclass class _: this_is_not_fine: list[int] = f() # RUF009: Do not perform function call `f` in dataclass defaults this_is_also_not: int = f() # RUF009: Do not perform function call `f` in dataclass defaults ``` After PR: ``` def _( this_is_fine: int = f(), # No error this_is_not: list[int] = f() # B008: Do not perform function call `f` in argument defaults ): ... @dataclass class _: this_is_not_fine: list[int] = f() # RUF009: Do not perform function call `f` in dataclass defaults this_is_fine: int = f() ```
This commit is contained in:
parent
07cf8852a3
commit
d2f661f795
4 changed files with 29 additions and 107 deletions
|
@ -97,3 +97,16 @@ class DataclassWithNewTypeFields:
|
|||
# No errors
|
||||
e: SpecialString = SpecialString("Lorem ipsum")
|
||||
f: NegativeInteger = NegativeInteger(-110)
|
||||
|
||||
|
||||
# Test for:
|
||||
# https://github.com/astral-sh/ruff/issues/15772
|
||||
def f() -> int:
|
||||
return 0
|
||||
|
||||
@dataclass
|
||||
class ShouldMatchB008RuleOfImmutableTypeAnnotationIgnored:
|
||||
this_is_not_fine: list[int] = default_function()
|
||||
# ignored
|
||||
this_is_fine: int = f()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue