Fix invalid reference to ruff_options.rs by charliermarsh · Pull Request #1409 · astral-sh/ruff (original) (raw)

@charliermarsh

renovate Bot referenced this pull request in ixm-one/pytest-cmake-presets

Dec 28, 2022

@renovate

saada added a commit to saada/ruff that referenced this pull request

Oct 31, 2025

@saada

Resolves astral-sh#1409

Allow Final instance attributes to be initialized in init methods, as specified by the Python typing spec. Previously, ty incorrectly prevented this initialization.

Changes:

@saada saada mentioned this pull request

Oct 31, 2025

saada added a commit to saada/ruff that referenced this pull request

Oct 31, 2025

@saada

Resolves astral-sh#1409

Allow Final instance attributes to be initialized in init methods, as specified by the Python typing spec. Previously, ty incorrectly prevented this initialization.

Changes:

saada added a commit to saada/ruff that referenced this pull request

Oct 31, 2025

@saada

Per feedback from sharkdp and AlexWaygood, this allows Final instance attributes to be initialized in init methods as specified in PEP 591.

The implementation checks if we're in init before rejecting Final assignments at three key validation points in the attribute assignment logic.

Note: This does not yet detect reassignments within init or to already-assigned class attributes. These require flow-sensitive analysis and are documented as known limitations for future work.

All 278 mdtest tests pass.

Refs astral-sh#1409

saada added a commit to saada/ruff that referenced this pull request

Oct 31, 2025

@saada

Per feedback from sharkdp and AlexWaygood, this allows Final instance attributes to be initialized in init methods as specified in PEP 591.

The implementation adds init context checking at three key validation points where invalid_assignment_to_final is called.

Known limitations (require flow-sensitive analysis for future work):

These limitations are documented in the test file with TODO markers.

All 278 mdtest tests pass.

Refs astral-sh#1409

saada added a commit to saada/ruff that referenced this pull request

Oct 31, 2025

@saada

Per feedback from sharkdp and AlexWaygood, this allows Final instance attributes to be initialized in init methods as specified in PEP 591.

The implementation adds init context checking at three key validation points where invalid_assignment_to_final is called.

Known limitations (require flow-sensitive analysis for future work):

These limitations are documented in the test file with TODO markers.

All 278 mdtest tests pass.

Refs astral-sh#1409

saada added a commit to saada/ruff that referenced this pull request

Oct 31, 2025

@saada

Per feedback from sharkdp and AlexWaygood, this allows Final instance attributes to be initialized in init methods as specified in PEP 591.

The implementation adds an is_in_init() helper closure and modifies the existing invalid_assignment_to_final closure to check for init context. This centralizes the logic and avoids duplication across the three call sites.

Known limitations (require flow-sensitive analysis for future work):

These limitations are documented in the test file with TODO markers.

All 278 mdtest tests pass.

Refs astral-sh#1409

saada added a commit to saada/ruff that referenced this pull request

Oct 31, 2025

@saada

Resolves astral-sh#1409

Allow Final instance attributes to be initialized in init methods, as specified by the Python typing spec. Previously, ty incorrectly prevented this initialization.

Changes:

saada added a commit to saada/ruff that referenced this pull request

Oct 31, 2025

@saada

Per feedback from sharkdp and AlexWaygood, this allows Final instance attributes to be initialized in init methods as specified in PEP 591.

The implementation adds an is_in_init() helper closure and modifies the existing invalid_assignment_to_final closure to check for init context. This centralizes the logic and avoids duplication across the three call sites.

Known limitations (require flow-sensitive analysis for future work):

These limitations are documented in the test file with TODO markers.

All 278 mdtest tests pass.

Refs astral-sh#1409

saada added a commit to saada/ruff that referenced this pull request

Nov 6, 2025

@saada

The implementation now checks:

  1. We're in a function named init
  2. The function is a method (has class context)
  3. The object type matches the class we're in (handles both NominalInstance and Self types)

This prevents false negatives where Final attributes could be assigned from:

All 280 mdtest tests pass.

Refs astral-sh#1409

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})