Skip to content

Fix self type check for generic NamedTuple with constrained typevar - #22119

Open
EmmanuelNiyonshuti wants to merge 2 commits into
python:masterfrom
EmmanuelNiyonshuti:fix/constrained-generic-type-params-in-namedtuple
Open

EmmanuelNiyonshuti wants to merge 2 commits into
python:masterfrom
EmmanuelNiyonshuti:fix/constrained-generic-type-params-in-namedtuple

Conversation

@EmmanuelNiyonshuti

Copy link
Copy Markdown
Contributor

Fixes #21453

This PR makes it so that, for generic NamedTuples with a constrained typevar
and an unannotated self, the signature's self type with the substituted typevar
instance is used to substitute the ref_type(the class type seen from inside
the method), and they are the same type.
Otherwise the same-type check was failing, since ref_type would stay a typevar
type.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

scipy-stubs (https://github.com/scipy/scipy-stubs)
+ tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

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.

Error on generic NamedTuple method that uses constrained type parameter

1 participant