You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Internal error occurs at @typing.overload in large protoc generated files #22257
When running mypy on some large protoc generated python files, it consistently returns an internal error at the same line. Unfortunately, after mypy returns this internal error, I cannot copy the contents of the command prompt. I will paste a screenshot of the error report and traceback in the traceback section.
Traceback
To Reproduce
I've attached source code to reproduce this. I was using poetry to build and run mypy, so the steps I performed are:
Open command prompt to the package root
Run poetry build && poetry install
Run poetry run mypy
See mypy take a long time and eventually fail with an internal error.
Your Environment
Mypy version used: 2.4.0
Mypy command-line flags: --show-traceback
Mypy configuration options from mypy.ini (and other config files): None
Thanks for the repro. The crash is a MemoryError from a combinatorial explosion. MetadataStoreServiceStub is generic in 34 value-restricted TypeVars (2 values each). When checking the __init__ overloads, mypy expands every combination of those class TypeVars (2^34) in expand_callable_variants(), even though the overload signatures (explicit concrete self: types) don't use any of them. The same happens again when the overload items are type checked (TypeChecker.expand_typevars()).
Minimal repro (as a .pyi; with ~16 TypeVars it already takes minutes on master):
Skipping type variables that don't appear in the signature fixes it without changing semantics (substituting an unused type variable is a no-op). I'll open a PR. Related: #20439, nipunn1313/mypy-protobuf#707.
Activity
EmmanuelNiyonshuti commentedon Oct 21, 2026
I'm not seeing the attached source code on the issue?
mjohanse-emr commentedon Oct 21, 2026
Adding attachment that I forgot on creation.
mypy-bug-repro.zip
mjohanse-emr commentedon Oct 21, 2026
@EmmanuelNiyonshuti sorry about that, I forgot to attach when I created. I just commented with the attachment.
MustafaKemal0146 commentedon Oct 26, 2026
Thanks for the repro. The crash is a
MemoryErrorfrom a combinatorial explosion.MetadataStoreServiceStubis generic in 34 value-restricted TypeVars (2 values each). When checking the__init__overloads, mypy expands every combination of those class TypeVars (2^34) inexpand_callable_variants(), even though the overload signatures (explicit concreteself:types) don't use any of them. The same happens again when the overload items are type checked (TypeChecker.expand_typevars()).Minimal repro (as a
.pyi; with ~16 TypeVars it already takes minutes on master):Skipping type variables that don't appear in the signature fixes it without changing semantics (substituting an unused type variable is a no-op). I'll open a PR. Related: #20439, nipunn1313/mypy-protobuf#707.