We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hello,
mypy thinks that some variable can never be None when the typing and the default value clearly indicate otherwise.
Was already declared for 2.3 #7399, fixed until 2.6.3 and it seems to be back again for version 2.6.4.
import pydantic class ModelNested(pydantic.BaseModel): my_var: str | None = pydantic.Field(default=None) class Model(ModelNested): pass m = Model() if m.my_var is None: print("hello there") # test.py:14: error: Statement is unreachable [unreachable]
pydantic version: 2.6.4 pydantic-core version: 2.16.3 pydantic-core build: profile=release pgo=true install path: ... python version: 3.12.2 (main, Feb 14 2024, 11:13:34) [Clang 15.0.0 (clang-1500.1.0.2.5)] platform: macOS-14.4-arm64-arm-64bit related packages: fastapi-0.110.0 mypy-1.9.0 typing_extensions-4.10.0 pydantic-settings-2.2.1 commit: unknown
[tool.mypy] strict = true warn_unreachable = true exclude = [".venv"] show_error_codes = true plugins = ["pydantic.mypy"] [[tool.mypy.overrides]] module = [ "deepdiff.*", "vcr.*", "voluptuous.*", "msgpack.*", "bs4.*", "graphql_utils", "markdownify", "asgi_lifespan", "authlib.*", "imia.*", "starsessions.*", "sqlalchemy_utils.*", "alembic_utils.*", "google.*", ] ignore_missing_imports = true
The text was updated successfully, but these errors were encountered:
Should be fixed in 2.7, coming out soon! Fixed by @dmontagu here: #9008
Sorry, something went wrong.
dmontagu
No branches or pull requests
Initial Checks
Description
Hello,
mypy thinks that some variable can never be None when the typing and the default value clearly indicate otherwise.
Was already declared for 2.3 #7399, fixed until 2.6.3 and it seems to be back again for version 2.6.4.
Example Code
Python, Pydantic & OS Version
mypy settings
The text was updated successfully, but these errors were encountered: