Skip to content

False positive with RUF009 using NewType, Final and dataclass #6447

@inkhey

Description

@inkhey

Hello 👋 , I think I found a false positive on RUF009 rule.

test_ruff.py:

from dataclasses import dataclass
from typing import Final, NewType

State = NewType("State", str)


@dataclass
class System:
    state: Final[State] = State("Enabled")


@dataclass
class System2:
    state: Final[str] = "Enabled"

version:

❯ ruff --version
ruff 0.0.283

bug.toml:

select = ["RUF"]

output:

❯ ruff check --config=bug.toml test_ruff.py 
test_ruff.py:9:27: RUF009 Do not perform function call `State` in dataclass defaults
Found 1 error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtype-inferenceRequires more advanced type inference.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions