Update typeddicts_class_syntax.py test to use a custom metaclass. - #2327
Merged
Conversation
The TypedDict chapter of the spec says: > It is also invalid to specify a custom metaclass. It looks like most type checkers interpret this to mean that the appearance of `metaclass=...` is illegal in a TypedDict definition. Pyrefly interprets this to mean that a non-`type` metaclass is illegal, so a redundant `metaclass=type` is fine. IMO either interpretation is defensible, but the conformance test currently uses `metaclass=type`, which only accommodates the first. This PR changes the test to use a non-`type` metaclass, which is unambiguously an error. This doesn't actually change pyrefly's conformance results because pyrefly has a bug that causes it to emit a different, nonsensical error on the `metaclass=type` line, which was mistakenly taken as pyrefly passing the test. I'm in the process of fixing that bug, which is how I discovered that pyrefly behaves slightly differently from the other checkers here.
davidhalter
approved these changes
Aug 2, 2026
davidhalter
left a comment
Collaborator
There was a problem hiding this comment.
This seems to map with runtime behavior:
>>> from typing import *
>>> class BadTypedDict2(TypedDict, metaclass=type): pass
...
>>> class CustomMeta(type):
... pass
...
>>> class BadTypedDict2(TypedDict, metaclass=CustomMeta): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
JelleZijlstra
approved these changes
Aug 3, 2026
meta-codesync Bot
pushed a commit
to facebook/pyrefly
that referenced
this pull request
Aug 3, 2026
Summary: Updates conformance tests to pull in python/typing#2327. Reviewed By: ndmitchell Differential Revision: D114618365 fbshipit-source-id: 0b81efb5df3f5356e0b94df6dea551898031b1e9
rchen152
added a commit
to rchen152/pyrefly
that referenced
this pull request
Aug 3, 2026
Summary: It's pointless but perfectly legal to write `metaclass=type`. ~~The conformance change is because pyrefly previously accidentally passed a test due to emitting a FP on a line on which an entirely different error is expected. I believe pyrefly's behavior as of this diff is correct and the test is overly strict: I've opened python/typing#2327 to adjust the test.~~ The conformance test has been updated :) Reviewed By: yangdanny97 Differential Revision: D114434451
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.
The TypedDict chapter of the spec says (emphasis mine):
It looks like most type checkers interpret this to mean that the appearance of
metaclass=...is illegal in a TypedDict definition.Pyrefly interprets this to mean that a non-
typemetaclass is illegal, so a redundantmetaclass=typeis fine.IMO either interpretation is defensible, but the conformance test currently uses
metaclass=type, which only accommodates the first. This PR changes the test to use a non-typemetaclass, which is unambiguously an error.This doesn't actually change pyrefly's conformance results because pyrefly has a bug that causes it to emit a different, nonsensical error on the
metaclass=typeline, which was mistakenly taken as pyrefly passing the test. I'm in the process of fixing that bug, which is how I discovered that pyrefly behaves slightly differently from the other checkers here.