[ty] Reject generic metaclasses parameterized by type variables#23628
Merged
AlexWaygood merged 3 commits intomainfrom Feb 28, 2026
Merged
[ty] Reject generic metaclasses parameterized by type variables#23628AlexWaygood merged 3 commits intomainfrom
AlexWaygood merged 3 commits intomainfrom
Conversation
Generic metaclasses are not supported per the typing spec. This adds a check that rejects `metaclass=SomeGeneric[T]` with an `invalid-metaclass` error when the metaclass argument is a parameterized generic class. https://claude.ai/code/session_01Nhdsupjg85NjKVFHSTZR9x
…ble parameters Generic metaclasses parameterized by type variables are not supported per the typing spec. `metaclass=Meta[int]` (fully specialized) is fine, but `metaclass=Meta[T]` (parameterized by type variables) is not. This adds a check in `try_metaclass` that detects when the explicit metaclass is a `GenericAlias` whose specialization contains type variables, and emits an `invalid-metaclass` diagnostic. https://claude.ai/code/session_01Nhdsupjg85NjKVFHSTZR9x
Typing conformance results improved 🎉The percentage of diagnostics emitted that were expected errors increased from 85.38% to 85.39%. The percentage of expected errors that received a diagnostic increased from 75.92% to 76.01%. Summary
True positives addedDetails
|
|
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
0 | 1 | 0 |
| Total | 0 | 1 | 0 |
charliermarsh
approved these changes
Feb 28, 2026
carljm
added a commit
that referenced
this pull request
Mar 2, 2026
* main: [ty] Move binary expression logic out of `builder.rs` (#23649) [ty] Limit recursion depth when displaying self-referential function types (#23647) [ty] Move comparison logic out of `builder.rs` (#23646) Avoid inserting redundant `None` elements in UP045 (#23459) [ty] Add more ParamSpec validation for `P.args` and `P.kwargs` (#23640) [ty] Sync vendored typeshed stubs (#23642) [ty] Fix inference of `t.__mro__` if `t` is an instance of `type[Any]` (#23632) [ty] Detect inconsistent generic base class specializations (#23615) [ty] Validate type variable defaults don't reference later type parameters or type parameters out of scope (#23623) [ty] Ban nested `Required`/`NotRequired`, and ban them both outside of `TypedDict` fields (#23627) [ty] Reject generic metaclasses parameterized by type variables (#23628) Update default Python version examples (#23605) fix binops with NewType of float and Unknown (#23620) [ty] Reject functions with PEP-695 type parameters that shadow type parameters from enclosing scopes (#23619) [ty] Reject ellipsis literals in odd places in type/annotation expressions (#23611) [ty] hash-cons `UseDefMap` fields (#23283)
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
Add validation to reject generic metaclasses that are parameterized by type variables, as these are banned by the typing spec.
Test Plan
mdtests