[ty] Do not consider a subclass of a @dataclass_transform-decorated class to have dataclass-like semantics if it has type in its MRO#24679
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 87.94%. The percentage of expected errors that received a diagnostic held steady at 83.36%. The number of fully passing files held steady at 79/133. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
trio
flake8
|
02d9a7b to
bc613cf
Compare
AlexWaygood
commented
Apr 16, 2026
| Person("Bob", email="bob@example.com", notes="other notes") | ||
| ``` | ||
|
|
||
| #### Inherited metaclass-based transformer |
Member
Author
There was a problem hiding this comment.
we moved this test up, because it seemed to incorrectly be in the "Field specifiers using **kwargs" section, despite not having much to do with field specifiers that use **kwargs
|
… class to have dataclass-like semantics if it has `type` in its MRO
bc613cf to
68ab287
Compare
carljm
approved these changes
Apr 16, 2026
This was referenced Apr 27, 2026
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
Currently we consider both subclasses of
RegistryMetaand instances ofRegistryMetato have dataclass-like semantics in the following snippet:According to a strict reading of the spec, this is the correct behaviour:
However, the practical effect of this would be that
SubclassOfis no longer usable as a metaclass -- and since it is an instance oftype, that's probably how the user actually wants to use it! A class can only be soundly usable as a metaclass if it is callable with the same parameters asbuiltins.type-- but if havingRegistryMetain its MRO would lead to a new__init__signature being synthesized forSubclassOf,SubclassOfwill no longer be usable as a metaclass. That means that when we start checking the arguments implicit passed to metaclass constructors (as part of #24550), it will break the feature added in #24615 whereby classes that haveSubclassOfas their metaclass would also be considered as having dataclass-like semantics.This doesn't seem like desirable behaviour, so this PR adds a heuristic whereby if we see that a class inheriting from a
@dataclass_transform-decorated class hastypein its MRO, we will not bestow dataclass-like semantics onto that class; we will assume that the@dataclass_transform-decorated class only provides dataclass-like semantics to classes that have that class as their metaclass.Test Plan
mdtests updated
Co-authored-by: Carl Meyer carl@astral.sh