-
-
Notifications
You must be signed in to change notification settings - Fork 64
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 plugin reports false positives and not existing lines #403
Comments
Thanks @febus982 for reporting this issue. we will try to fix the problem. |
I get the same 'error: X | Y syntax for unions requires Python 3.10 [syntax]' for the following file:
I'm pretty sure there's no '|' in there. 😃 What's really strange is that I do not get the error in the CI-pipeline, which uses the exact same versions. I deleted the .mypy_cache folder multiple times but the error persists. |
The error is related Python < 3.10, because the signature of def __init__(
__pydantic_self__,
_case_sensitive: bool | None = None,
_nested_model_default_partial_update: bool | None = None,
_env_prefix: str | None = None,
_env_file: DotenvType | None = ENV_FILE_SENTINEL,
_env_file_encoding: str | None = None,
_env_ignore_empty: bool | None = None,
_env_nested_delimiter: str | None = None,
_env_parse_none_str: str | None = None,
_env_parse_enums: bool | None = None,
_cli_prog_name: str | None = None,
_cli_parse_args: bool | list[str] | tuple[str, ...] | None = None,
_cli_settings_source: CliSettingsSource[Any] | None = None,
_cli_parse_none_str: str | None = None,
_cli_hide_none_type: bool | None = None,
_cli_avoid_json: bool | None = None,
_cli_enforce_required: bool | None = None,
_cli_use_class_docs_for_groups: bool | None = None,
_cli_exit_on_error: bool | None = None,
_cli_prefix: str | None = None,
_cli_implicit_flags: bool | None = None,
_secrets_dir: PathType | None = None,
**values: Any,
) -> None: You need to maintain backward compatibility or make separate releases for each Python version |
I temporarily patched by specifying: [tool.mypy]
plugins = "pydantic.mypy"
# Suppress errors since pydantic_settings uses X | Y typing
python_version = "3.10" In the configuration. |
Bug Report
mypy identifies false positive
X | Y
errors on not existing lines ifpydantic.mypy
plugin is enabled.Note that I cannot find any instance of
X | Y
in the whole repository.To Reproduce
This is the file: https://github.com/febus982/bootstrap-python-fastapi/blob/main/src/bootstrap/config.py
Command used:
mypy --python-version 3.9 --no-incremental
from the root repository directory.Expected Behavior
No errors reported
Actual Behavior
Note that the
src/bootstrap/config.py
file is only 64 lines longYour Environment
mypy 1.11.2 (compiled: yes)
--python-version 3.9
(also--no-incremental
to show line numbers but the error persists without)mypy.ini
(and other config files): from pyproject.tomlpydantic==2.9.1
andpydantic-settings==2.5.3
- the issue didn't occur onpydantic==2.8.2
andpydantic-settings==2.3.4
The text was updated successfully, but these errors were encountered: