Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B008 doesn't report when the annotation refers to an immutable type, but RUF009 does #15772

Open
InSyncWithFoo opened this issue Jan 27, 2025 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@InSyncWithFoo
Copy link
Contributor

InSyncWithFoo commented Jan 27, 2025

Minimal reproducible example (playground):

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

RUF009 should behave similar to B008 and ignore attributes with immutable types.

@InSyncWithFoo
Copy link
Contributor Author

This should make for a good first issue.

@dhruvmanila
Copy link
Member

Yeah, this seems reasonable. I think it's because we don't look at the annotation which can be done using is_immutable_annotation.

@dhruvmanila dhruvmanila added bug Something isn't working good first issue Good for newcomers labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants