Skip to content

Update typeddicts_class_syntax.py test to use a custom metaclass. - #2327

Open
rchen152 wants to merge 1 commit into
python:mainfrom
rchen152:typeddict
Open

Update typeddicts_class_syntax.py test to use a custom metaclass.#2327
rchen152 wants to merge 1 commit into
python:mainfrom
rchen152:typeddict

Conversation

@rchen152

@rchen152 rchen152 commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

The TypedDict chapter of the spec says (emphasis mine):

It is invalid to specify a base class other than TypedDict, Generic, or another TypedDict type in a class-based TypedDict definition. 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.

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.
@srittau srittau added the topic: conformance tests Issues with the conformance test suite label Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: conformance tests Issues with the conformance test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants