Skip to content
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

False X | Y positives on not existing lines #17768

Closed
febus982 opened this issue Sep 13, 2024 · 1 comment
Closed

False X | Y positives on not existing lines #17768

febus982 opened this issue Sep 13, 2024 · 1 comment
Labels
bug mypy got something wrong

Comments

@febus982
Copy link

Bug Report

mypy identifies false positive X | Y errors on not existing lines.

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

from pathlib import Path
from typing import Dict, Literal, Optional

from pydantic import BaseModel
from pydantic_settings import BaseSettings, SettingsConfigDict
from sqlalchemy_bind_manager import SQLAlchemyConfig

TYPE_ENVIRONMENT = Literal["local", "test", "staging", "production"]


class CeleryConfig(BaseModel):
    # https://docs.celeryq.dev/en/stable/userguide/configuration.html#configuration

    timezone: str = "UTC"

    # Broker config
    broker_url: Optional[str] = None
    broker_connection_retry_on_startup: bool = True

    # Results backend config
    result_backend: Optional[str] = None
    redis_socket_keepalive: bool = True

    # Enable to ignore the results by default and not produce tombstones
    task_ignore_result: bool = False

    # We want to use the default python logger configured using structlog
    worker_hijack_root_logger: bool = False

    # Events enabled for monitoring
    worker_send_task_events: bool = True
    task_send_sent_event: bool = True

    # Recurring tasks triggered directly by Celery
    beat_schedule: dict = {}
    # beat_schedule: dict = {
    #     "recurrent_example": {
    #         "task": "domains.books._tasks.book_cpu_intensive_task",
    #         "schedule": 5.0,
    #         "args": ("a-random-book-id",),
    #     },
    # }


class AppConfig(BaseSettings):
    model_config = SettingsConfigDict(env_nested_delimiter="__")

    APP_NAME: str = "bootstrap"
    CELERY: CeleryConfig = CeleryConfig()
    DEBUG: bool = False
    ENVIRONMENT: TYPE_ENVIRONMENT = "local"
    SQLALCHEMY_CONFIG: Dict[str, SQLAlchemyConfig] = dict(
        default=SQLAlchemyConfig(
            engine_url=f"sqlite+aiosqlite:///{Path(__file__).parent.parent.joinpath('sqlite.db')}",
            engine_options=dict(
                connect_args={
                    "check_same_thread": False,
                },
                echo=False,
                future=True,
            ),
            async_engine=True,
        ),
    )

Command used: mypy --python-version 3.9 --no-incremental from the root repository directory.

Expected Behavior

Actual Behavior

Note that the file is 64 lines long

src/bootstrap/config.py:128: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:129: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:130: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:131: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:132: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:133: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:134: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:135: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:136: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:137: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:138: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:139: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:140: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:141: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:142: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:143: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:144: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:145: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:146: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:147: error: X | Y syntax for unions requires Python 3.10  [syntax]
src/bootstrap/config.py:148: error: X | Y syntax for unions requires Python 3.10  [syntax]
Found 21 errors in 1 file (checked 63 source files)

Your Environment

  • Mypy version used: mypy 1.11.2 (compiled: yes)
  • Mypy command-line flags: --python-version 3.9 (also --no-incremental to show line numbers but the error persists without)
  • Mypy configuration options from mypy.ini (and other config files): from pyproject.toml
[tool.mypy]
files = ["src", "tests"]
exclude = ["alembic"]
plugins = "pydantic.mypy,strawberry.ext.mypy_plugin"

# We can remove celery by installing `celery-types` but needs
# at least python 3.10. For now we maintain the override.
[[tool.mypy.overrides]]
module = [
    "celery.*"
]
ignore_missing_imports = true
  • Python version used: Python 3.11.9 (but experienced also directly on 3.9 and 3.12)
@febus982 febus982 added the bug mypy got something wrong label Sep 13, 2024
@febus982
Copy link
Author

It seems to be caused by pydantic.mypy plugin, I'll close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant