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
from typing import NamedTuple
class CodecKey(NamedTuple):
"""A key object combines type and version."""
@staticmethod
def from_key_str(key: str) -> "CodecKey":
"""Return a CodecKey parsed from a key string.
A codec key string has a format of f"{type_keytag}/{version}"
"""
type_keytag, version = key.split("/")
return CodecKey(type_keytag, version)
Hmm, I can't seem reproduce a crash. Tested with mypy v1.13.0 (compiled) and master, Python 3.12.7.
Can you think of anything else that might help narrow this down? Also, can you try to reduce the reproducer to the minimum required code, config, and flags?
from typing import NamedTuple
class CodecKey(NamedTuple):
"""A key object combines type and version."""
@staticmethod
def from_key_str(key: str) -> "CodecKey":
"""Return a CodecKey parsed from a key string.
A codec key string has a format of f"{type_keytag}/{version}"
"""
type_keytag, version = key.split("/")
return CodecKey(type_keytag, version)
Thanks for the reduced repro! I can reproduce this on master. The necessary elements seems to be
setting follow_imports = skip for importlib. This causes the semantic analyzer to defer on every (non-final) pass due to importlib.machinery.ModuleSpec being missing. There's already logic in place to fall back to builtins.object on the final pass; however the final pass is never reached (see below).
a NamedTuple with a function definition. In this case, a new symbol table node is created for the function on every pass, causing the semantic analyzer to always "make progress". Since it makes progress on every pass, the final iteration is never reached.
The result is that the semantic analyzer always defers due to (1) and always makes progress due to (2). This leads to an infinite number of passes (until the max iteration logic kicks in).
Mypy is crashing in this example (currently works with 1.0.9)
Crash Report
To Reproduce
file to repro
Your Environment
--show-traceback
mypy.ini
The text was updated successfully, but these errors were encountered: