[ty] Detect invalid uses of @final on non-methods#23604
Merged
AlexWaygood merged 6 commits intomainfrom Feb 27, 2026
Merged
Conversation
…functions Per the typing spec, `@final` is only valid on methods and classes. Using it on a module-level function or a nested function is an error. This adds a new `final-on-non-method` lint rule that detects this misuse and emits a diagnostic. This should cause the upstream conformance test `qualifiers_final_decorator.py` to pass, as the only previously missing check was for `@final` applied to non-method functions. https://claude.ai/code/session_015ajybUNEuqCYeVVnSsiFCS
- Use let chains instead of nested if blocks - Remove redundant tests (typing_extensions, methods, classes are tested elsewhere) - Add test for @Final on function nested inside a method - Fix version to 0.0.20 https://claude.ai/code/session_015ajybUNEuqCYeVVnSsiFCS
Typing conformance results improved 🎉The percentage of diagnostics emitted that were expected errors increased from 85.20% to 85.21%. The percentage of expected errors that received a diagnostic increased from 75.44% to 75.53%. Summary
True positives addedDetails
|
|
Memory usage reportMemory usage unchanged ✅ |
Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
d070c2e to
75b7896
Compare
carljm
added a commit
that referenced
this pull request
Feb 27, 2026
* main: [ty] Take myself out of the reviewer pool for the next few days (#23618) [ty] Fix bug where ty would think that a `Callable` with a variadic positional parameter could be a subtype of a `Callable` with a positional-or-keyword parameter (#23610) [`ruff`] Add fix for `none-not-at-end-of-union` (`RUF036`) (#22829) Bump cargo dist to 0.31 (#23614) [`pyflakes`] Fix false positive for names shadowing re-exports (`F811`) (#23356) [`fastapi`] Handle callable class dependencies with `__call__` method (`FAST003`) (#23553) [ty] Recurse into tuples and nested tuples when applying special-cased validation of `isinstance()` and `issubclass()` (#23607) Update typing conformance suite commit (#23606) [ty] Detect invalid uses of `@final` on non-methods (#23604) [ty] Move the type hierarchy request handlers to individual modules [ty] Wire up the type hierarchy implementation with the LSP [ty] Add routine for mapping from system path to vendored path [ty] Implement internal routines for providing the LSP "type hierarchy" feature [ty] Add some helper methods on `ClassLiteral` [ty] Move some module name helper routines to methods on `ModuleName` [ty] Bump version of `lsp-types` [ty] Refactor to support building constraint sets differently (#23600) [ty] Dataclass transform: neither frozen nor non-frozen (#23366) [ty] Add snapshot tests for advanced `invalid-assignment` scenarios (#23581) [ty] disallow negative narrowing on SubclassOf types (#23598)
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
This fixes the last remaining conformance failure on https://github.com/python/typing/blob/main/conformance/tests/qualifiers_final_decorator.py
Test Plan
mdtests