[ty] Detect overrides of Final class variables in subclasses#23180
Merged
charliermarsh merged 1 commit intomainfrom Feb 11, 2026
Merged
[ty] Detect overrides of Final class variables in subclasses#23180charliermarsh merged 1 commit intomainfrom
Final class variables in subclasses#23180charliermarsh merged 1 commit intomainfrom
Conversation
Typing conformance results improved 🎉The percentage of diagnostics emitted that were expected errors increased from 82.54% to 82.56%. The percentage of expected errors that received a diagnostic increased from 73.84% to 73.94%. Summary
True positives addedDetails
|
|
Address review findings (job 56) All tests pass. Here's a summary of what was done: Changes: - Guard `own_class_member` lookup behind a check that at least one of `check_final_method_overridden()` or `check_final_variable_overridden()` is enabled, avoiding an unnecessary query per superclass per member when both checks are disabled - Make `superclass_symbol_id` non-gating in the final variable check — use `Option::and_then` instead of `?` early-return, since the symbol ID is only needed for the declaration lookup (secondary annotation), not for the `FINAL` qualifiers check itself Address review findings (job 58) All tests pass. The change is minimal — only finding #2 needed to be addressed since: - **Finding #1 (Medium)**: Already fixed in the prior commit (29088ca) — the `own_class_member()` call is already guarded by the `if configuration.check_final_method_overridden() || configuration.check_final_variable_overridden()` check. - **Finding #2 (Low)**: Added a comment noting the shared `own_class_member` lookup. - **Finding #3 (Low)**: Already covered — the "Basic override detection" test at line 318-319 explicitly verifies the diagnostic message says `"Cannot override final variable `FINAL_B` from superclass `Base`"` for the `Final`-re-declaration case. Changes: - Add comment documenting that `own_class_member` lookup is shared between the final-method and final-variable override checks Address review findings (job 60) All tests pass. The change is minimal - just removing a narrating comment that doesn't add value. Changes: - Remove narrating comment on the shared `own_class_member` lookup, as the code is self-explanatory Address review findings (job 62) All tests pass, all pre-commit checks pass. Changes: - Added test for `@override` decorator interaction with `Final` variable overrides, verifying that `override-of-final-variable` is emitted while `invalid-explicit-override` is not (since the member does exist in the superclass) Address review findings (job 64) All changes are complete. Here's the summary: Changes: - Guard `own_class_member` lookup with `is_none()` checks to avoid unnecessary Salsa query when both `overridden_final_method` and `overridden_final_variable` are already found - Add `qualifiers()` accessor to `Member` and use it instead of direct `.inner.qualifiers` field access, consistent with the wrapper pattern used by other `Member` methods - Clarify test description for `@override` on `Final` variable override to note that `@override` can only be applied to methods, not variable assignments Address review findings (job 66) All tests pass. The change is minimal — only a comment was needed since the reviewer found no bugs, just areas that could benefit from documentation. Changes: - Added comment in `report_overridden_final_variable` explaining when the `superclass_definition: None` fallback path is hit (e.g. stubs without source or compiled extension modules)
bf1d422 to
bad94a4
Compare
Memory usage reportMemory usage unchanged ✅ |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
override-of-final-variablediagnostic that flags subclass attributes that override a superclass attribute declared asFinal.Closes astral-sh/ty#871.