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

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

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

smokyabdulrahman
Copy link
Contributor

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()

Copy link
Contributor

github-actions bot commented Feb 8, 2025

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+0 -12 violations, +0 -0 fixes in 2 projects; 53 projects unchanged)

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

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

- airflow/models/dag.py:432:25: RUF009 Do not perform function call in dataclass defaults
- airflow/models/dag.py:433:24: RUF009 Do not perform function call `airflow_conf.get_mandatory_value` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/common_build_params.py:61:31: RUF009 Do not perform function call `os.environ.get` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/common_build_params.py:62:27: RUF009 Do not perform function call `os.environ.get` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/common_build_params.py:64:25: RUF009 Do not perform function call `os.environ.get` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/shell_params.py:151:31: RUF009 Do not perform function call `os.environ.get` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/shell_params.py:164:27: RUF009 Do not perform function call `os.environ.get` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/shell_params.py:166:25: RUF009 Do not perform function call `os.environ.get` in dataclass defaults

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

- src/latch_cli/exceptions/handler.py:23:23: RUF009 Do not perform function call `platform.version` in dataclass defaults
- src/latch_cli/exceptions/handler.py:24:26: RUF009 Do not perform function call `get_local_package_version` in dataclass defaults
- src/latch_cli/exceptions/handler.py:26:21: RUF009 Do not perform function call `platform.platform` in dataclass defaults
- src/latch_sdk_config/latch.py:86:22: RUF009 Do not perform function call `urljoin` in dataclass defaults

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF009 12 0 12 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -12 violations, +0 -0 fixes in 2 projects; 53 projects unchanged)

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

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

- airflow/models/dag.py:432:25: RUF009 Do not perform function call in dataclass defaults
- airflow/models/dag.py:433:24: RUF009 Do not perform function call `airflow_conf.get_mandatory_value` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/common_build_params.py:61:31: RUF009 Do not perform function call `os.environ.get` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/common_build_params.py:62:27: RUF009 Do not perform function call `os.environ.get` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/common_build_params.py:64:25: RUF009 Do not perform function call `os.environ.get` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/shell_params.py:151:31: RUF009 Do not perform function call `os.environ.get` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/shell_params.py:164:27: RUF009 Do not perform function call `os.environ.get` in dataclass defaults
- dev/breeze/src/airflow_breeze/params/shell_params.py:166:25: RUF009 Do not perform function call `os.environ.get` in dataclass defaults

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

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

- src/latch_cli/exceptions/handler.py:23:23: RUF009 Do not perform function call `platform.version` in dataclass defaults
- src/latch_cli/exceptions/handler.py:24:26: RUF009 Do not perform function call `get_local_package_version` in dataclass defaults
- src/latch_cli/exceptions/handler.py:26:21: RUF009 Do not perform function call `platform.platform` in dataclass defaults
- src/latch_sdk_config/latch.py:86:22: RUF009 Do not perform function call `urljoin` in dataclass defaults

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF009 12 0 12 0 0

@MichaReiser MichaReiser changed the title #15772 RUF009 should behave similar to B008 and ignore attributes with immutable types RUF009 should behave similar to B008 and ignore attributes with immutable types Feb 10, 2025
@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Feb 10, 2025
@MichaReiser
Copy link
Member

Thank you

@MichaReiser MichaReiser merged commit d2f661f into astral-sh:main Feb 10, 2025
21 checks passed
dcreager added a commit that referenced this pull request Feb 10, 2025
* main: (991 commits)
  [red-knot] Resolve `Options` to `Settings` (#16000)
  Bump version to 0.9.6 (#16074)
  Revert tailwindcss v4 update (#16075)
  Improve migration document (#16072)
  Fix reference definition labels for backtick-quoted shortcut links (#16035)
  RUF009 should behave similar to B008 and ignore attributes with immutable types (#16048)
  [`pylint`] Also report when the object isn't a literal (`PLE1310`) (#15985)
  Update Rust crate rustc-hash to v2.1.1 (#16060)
  Root exclusions in the server to project root (#16043)
  Directly include `Settings` struct for the server (#16042)
  Update Rust crate clap to v4.5.28 (#16059)
  Update Rust crate strum_macros to 0.27.0 (#16065)
  Update NPM Development dependencies (#16067)
  Update Rust crate uuid to v1.13.1 (#16066)
  Update Rust crate strum to 0.27.0 (#16064)
  Update pre-commit dependencies (#16063)
  Update dependency ruff to v0.9.5 (#16062)
  Update Rust crate toml to v0.8.20 (#16061)
  [`flake8-builtins`] Make strict module name comparison optional (`A005`) (#15951)
  [`ruff`] Indented form feeds (`RUF054`) (#16049)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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