New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mypy INTERNAL ERROR: maximum semantic analysis iteration count reached #8760
Comments
Could you please check if you're still having this issue with 2.6.1? Thanks! |
Replicates in 2.6.1, unfortunately
|
xref: pydantic/pydantic#8760 Fix the following error when testing with mypy: ``` $ tox -e mypy Deferral trace: cwltool.utils:62 cwltool.utils:-1 ... galaxy.model:666 galaxy.model:666 galaxy.model:666 galaxy.model:666 lib/galaxy/model/__init__.py: error: INTERNAL ERROR: maximum semantic analysis iteration count reached Found 1 error in 1 file (errors prevented further checking) ```
xref: pydantic/pydantic#8760 Fix the following error when testing with mypy: ``` $ tox -e mypy Deferral trace: cwltool.utils:62 cwltool.utils:-1 ... galaxy.model:666 galaxy.model:666 galaxy.model:666 galaxy.model:666 lib/galaxy/model/__init__.py: error: INTERNAL ERROR: maximum semantic analysis iteration count reached Found 1 error in 1 file (errors prevented further checking) ```
I have this issue as well with this sample: from typing import Annotated, Optional, Union
from pydantic import BaseModel, Field, field_validator, model_validator
class Origin(BaseModel):
x: Union[str, None]
def hello() -> None:
class Test(Origin):
@field_validator("x")
@classmethod
def validate_x(cls, value: Union[str, None]) -> Union[str, None]:
if value is not None and value == "":
raise ValueError("Not allowed")
return value mypy returns I'm using python3.9 and have these versions installed:
|
I have this issue as well with the same mypy error. The issue starts to occur with version Minimal reproThis repro is a stripped down version of a config file from a real application. The config file uses """Config for Application."""
from __future__ import annotations
import typing as t
# from pydantic_settings import BaseSettings
from pydantic import BaseModel as BaseSettings
class CustomBaseSettings(BaseSettings):
"""Custom base settings class with added functionality and set base config."""
class MySQLSettings(CustomBaseSettings):
"""MySQL settings with partial defaults."""
DB_MYSQL_PASSWORD: str | None
class Settings(t.Protocol):
"""Application Settings protocol."""
DB_MYSQL_SETTINGS: MySQLSettings | None
class _SettingsBase(CustomBaseSettings):
"""Shareable base settings."""
DB_MYSQL_SETTINGS: MySQLSettings | None = None
def get_prod_settings() -> Settings:
"""Return cached Production settings."""
class ProdMySQLSettings(MySQLSettings):
"""Production MySQL settings."""
class ProdSettings(_SettingsBase):
"""Production application settings."""
DB_MYSQL_SETTINGS: MySQLSettings | None = ProdMySQLSettings()
return ProdSettings() VersionsPython: $ python3 -VV
Python 3.11.7 (main, Dec 8 2023, 18:56:58) [GCC 11.4.0] Dependencies:
Mypy ConfigMypy config in [tool.mypy]
python_version = "3.11"
mypy_path = "mypy_stubs"
follow_imports = "silent"
disallow_any_generics = true
disallow_subclassing_any = true
disallow_untyped_defs = true
check_untyped_defs = true
strict_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_return_any = true
warn_unreachable = true
implicit_reexport = false
show_error_context = true
show_column_numbers = true
plugins = ["pydantic.mypy"]
[tool.pydantic-mypy]
init_forbid_extra = true
init_typed = false
warn_required_dynamic_aliases = true |
I believe this is all fixed by #9008, which should be included in the next release. |
I just tested against |
Initial Checks
Description
The code below causes mypy to crash with
INTERNAL ERROR: maximum semantic analysis iteration count reached
.It reproduces on pydantic 2.6.0 with the pydantic.mypy plugin enabled.
It does not reproduce on pydantic 2.5.3 or without the plugin.
The minimal reproducible example below is a bit strange and arbitrary. I have distilled it from a real codebase. It is not clear at all how the parts come together to cause the behavior, but almost any significant change to the code will solve the problem:
Optional
NamedTuple
doesn't have a methodExample Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: