Fix invalid reference to ruff_options.rs by charliermarsh · Pull Request #1409 · astral-sh/ruff (original) (raw)
renovate Bot referenced this pull request in ixm-one/pytest-cmake-presets
saada added a commit to saada/ruff that referenced this pull request
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:
- Modified attribute assignment validation to permit Final assignments when inside init methods
- Updated tests to reflect correct behavior
- Added test coverage for issue astral-sh#1409 with Self annotations
saada mentioned this pull request
saada added a commit to saada/ruff that referenced this pull request
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:
- Modified attribute assignment validation to permit Final assignments when inside init methods
- Updated tests to reflect correct behavior
- Added test coverage for issue astral-sh#1409 with Self annotations
saada added a commit to saada/ruff that referenced this pull request
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
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):
- Reassignment to class-level assigned Finals in init
- Multiple assignments to same Final within init
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
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):
- Reassignment to class-level assigned Finals in init
- Multiple assignments to same Final within init
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
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):
- Reassignment to class-level assigned Finals in init
- Multiple assignments to same Final within init
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
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:
- Modified attribute assignment validation to permit Final assignments when inside init methods
- Updated tests to reflect correct behavior
- Added test coverage for issue astral-sh#1409 with Self annotations
saada added a commit to saada/ruff that referenced this pull request
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):
- Reassignment to class-level assigned Finals in init
- Multiple assignments to same Final within init
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
- Remove unnecessary 'OK' comments from test assertions
- Fix false negatives: verify init is a method of the class being mutated
- Add test cases for invalid scenarios:
- Standalone functions named init
- Assignment from another class's init
- Assignment to non-self parameter (marked as TODO - requires parameter tracking)
The implementation now checks:
- We're in a function named init
- The function is a method (has class context)
- 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:
- Standalone functions named init
- Other classes' init methods
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 }})