Skip to content

Add missing __class_getitem__ methods to typing - #1062

Merged
Siyet merged 1 commit into
msgspec:mainfrom
sobolevn:add-missing-class-getitem
Jun 14, 2026
Merged

Add missing __class_getitem__ methods to typing#1062
Siyet merged 1 commit into
msgspec:mainfrom
sobolevn:add-missing-class-getitem

Conversation

@sobolevn

Copy link
Copy Markdown
Member

Runtime:

>>> import msgspec
>>> msgspec.json.Decoder.__class_getitem__((int,))
msgspec.json.Decoder[int]

Mypy:

» mypy -c 'import msgspec; msgspec.json.Decoder.__class_getitem__'
<string>:1: error: "type[Decoder[_T]]" has no attribute "__class_getitem__"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

Now this symbol would be defined.
I used the same definition that we use in typeshed: https://github.com/python/typeshed/blob/7e3b6cd8101ec0b80eedffa9a0ffd949f3ea88ab/stdlib/queue.pyi#L49

@Siyet

Siyet commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Thanks @sobolevn! Verified the stub matches runtime: both msgspec.json.Decoder and msgspec.msgpack.Decoder register __class_getitem__ via Py_GenericAlias (METH_CLASS) in _core.c, and at runtime Decoder[int] returns a real types.GenericAlias. These two are the only Generic classes in the stubs (Encoder is not generic), so coverage is complete. Merging.

@Siyet
Siyet added this pull request to the merge queue Jun 14, 2026
Merged via the queue into msgspec:main with commit 2b2e155 Jun 14, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants