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

[ruff] Implicit class variable in dataclass (RUF045) #14349

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

InSyncWithFoo
Copy link
Contributor

Summary

Resolves #12877.

Test Plan

cargo nextest run and cargo insta test.

Copy link
Contributor

github-actions bot commented Nov 15, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+16 -0 violations, +0 -0 fixes in 7 projects; 47 projects unchanged)

DisnakeDev/disnake (+2 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ disnake/ext/commands/params.py:378:9: RUF045 Assignment without annotation found in dataclass body
+ disnake/ext/commands/params.py:407:9: RUF045 Assignment without annotation found in dataclass body

apache/airflow (+4 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ airflow/executors/base_executor.py:85:5: RUF045 Assignment without annotation found in dataclass body
+ dev/breeze/src/airflow_breeze/params/doc_build_params.py:35:5: RUF045 Assignment without annotation found in dataclass body
+ task_sdk/src/airflow/sdk/definitions/baseoperator.py:1054:5: RUF045 Assignment without annotation found in dataclass body
+ task_sdk/src/airflow/sdk/definitions/baseoperator.py:1055:5: RUF045 Assignment without annotation found in dataclass body

latchbio/latch (+3 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ src/latch_cli/constants.py:31:5: RUF045 Assignment without annotation found in dataclass body
+ src/latch_cli/constants.py:32:5: RUF045 Assignment without annotation found in dataclass body
+ src/latch_cli/constants.py:39:5: RUF045 Assignment without annotation found in dataclass body

python/typeshed (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select E,F,FA,I,PYI,RUF,UP,W

+ stubs/fpdf2/fpdf/fonts.pyi:33:5: RUF045 Assignment without annotation found in dataclass body

scikit-build/scikit-build-core (+3 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ src/scikit_build_core/_logging.py:254:5: RUF045 Assignment without annotation found in dataclass body
+ src/scikit_build_core/file_api/model/codemodel.py:129:5: RUF045 Assignment without annotation found in dataclass body
+ src/scikit_build_core/file_api/model/directory.py:23:5: RUF045 Assignment without annotation found in dataclass body

pytest-dev/pytest (+2 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ src/_pytest/cacheprovider.py:64:5: RUF045 Assignment without annotation found in dataclass body
+ src/_pytest/cacheprovider.py:67:5: RUF045 Assignment without annotation found in dataclass body

pdm-project/pdm (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ src/pdm/project/config.py:81:5: RUF045 Assignment without annotation found in dataclass body

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF045 16 16 0 0 0

@InSyncWithFoo
Copy link
Contributor Author

InSyncWithFoo commented Nov 15, 2024

False positives found by ecosystem checks:

stubs/fpdf2/fpdf/fonts.pyi (@python/typeshed):

@dataclass
class FontFace:
    family: str | None
    emphasis: TextEmphasis | None
    size_pt: int | None
    color: DeviceGray | DeviceRGB | None
    fill_color: DeviceGray | DeviceRGB | None

    ...

    replace = dataclasses.replace

src/_pytest/fixtures.py (@pytest-dev/pytest):

@dataclasses.dataclass(frozen=True)
class FuncFixtureInfo:
    ...

    __slots__ = ("argnames", "initialnames", "names_closure", "name2fixturedefs")

Special names can be exempted, but I'm not sure what to do about the first.

@dhruvmanila dhruvmanila added rule Implementing or modifying a lint rule preview Related to preview mode features labels Nov 18, 2024
@MichaReiser
Copy link
Member

I'm not saying we shouldn't do it, but requiring type annotations has been controversial in other instances; for example, there's a long thread for RUF012 that does something similar. @AlexWaygood I'd be interested on your take on this before I start reviewing the rule itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn about un-annotated attributes in dataclass definition
3 participants