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
Mypy crashes on abstract class with generic type parameter #19946
It only defines a totally abstract class with a generic type parameter.
Traceback
src/nagas_api/weaver.py:7: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.18.1
Traceback (most recent call last):
File "mypy/semanal.py", line 7350, in accept
File "mypy/nodes.py", line 1440, in accept
File "mypy/semanal.py", line 1775, in visit_class_def
File "mypy/semanal.py", line 1916, in analyze_class
File "mypy/semanal.py", line 2222, in clean_up_bases_and_infer_type_variables
AssertionError:
src/nagas_api/weaver.py:7: : note: use --pdb to drop into pdb
Your Environment
Mypy version used: 1.18.1
Mypy command-line flags: uv run --active --group test mypy ./src --show-traceback --config-file ../pyproject.toml
Mypy configuration options from mypy.ini (and other config files):
Okay, but this doesn't seem to cause a crash? Neither your original snippet (SyntaxError, normally reported) nor the fixed one (with the missing semicolon restored and import abc added). Could you try to provide a working repro case?
During my attempts to reproduce this issue, I identified that the crash was caused by an import statement. When a "xxx" module uses __all__ statement to define the contents that can be included by import *, the issue is triggered when using from xxx import *. However, Mypy runs normally when importing explicitly via from xxx import (a, b, c, ...). While the exact root cause of the crash remains unclear, I have already identified a viable solution.
Oh, the star import probably brings another T into your namespace, then duplicate of #19526 or #18507. Could you please confirm that that your xxx module defines a symbol named T (either a type variable or something similar; may be imported transitively)?
In the first Python file(fileA), several classes with type parameters are defined, and all classes defined in this file are included in the __all__ list :
# some importsimportxxxclassOperatorA[I, O](abc.ABC):
...
classOperatorB[T](abc.ABC):
...
__all__= ["OperatorA", "OperatorB"]
Since we use Python 3.12's generic syntax, no symbols or type variables are declared using TypeVar.
The second Python file imports the first file,if it is imported in this way:
Activity
sterliakov commentedon Sep 28, 2025
Okay, but this doesn't seem to cause a crash? Neither your original snippet (SyntaxError, normally reported) nor the fixed one (with the missing semicolon restored and
import abcadded). Could you try to provide a working repro case?https://mypy-play.net/?mypy=1.18.1&python=3.13&flags=ignore-missing-imports%2Cdisallow-untyped-defs%2Cwarn-return-any&gist=e85b22f47263da6fff29585120eed653
bmmcq commentedon Sep 29, 2025
During my attempts to reproduce this issue, I identified that the crash was caused by an import statement. When a "xxx" module uses
__all__statement to define the contents that can be included byimport *, the issue is triggered when usingfrom xxx import *. However, Mypy runs normally when importing explicitly viafrom xxx import (a, b, c, ...). While the exact root cause of the crash remains unclear, I have already identified a viable solution.sterliakov commentedon Sep 29, 2025
Oh, the star import probably brings another
Tinto your namespace, then duplicate of #19526 or #18507. Could you please confirm that that yourxxxmodule defines a symbol namedT(either a type variable or something similar; may be imported transitively)?bmmcq commentedon Sep 29, 2025
Ok.
In the first Python file(fileA), several classes with type parameters are defined, and all classes defined in this file are included in the
__all__list :Since we use Python 3.12's generic syntax, no symbols or type variables are declared using TypeVar.
The second Python file imports the first file,if it is imported in this way:
mypy crashed as described above, but if import fileA like this:
mypy works well.
I think the second way also import some classes with type parameter "T" , but it works.
bmmcq commentedon Sep 29, 2025
And even if I change the generic 'T' to another name, like 'Z':
it still crashed at same place.
sterliakov commentedon Sep 29, 2025
Hm, this sounds more concerning, but I still can't reproduce.
Allow type parameters reusing the name missing from current module (#…