feluelle opened a new pull request, #76025: URL: https://github.com/apache/airflow/pull/76025
Airflow declares its ORM declarative base as `Base = Any` under `TYPE_CHECKING`. Since ty 0.0.52 (astral-sh/ruff#26034), a class that explicitly inherits from `Any` is treated as possibly being any type, including `None`. Reading a `Mapped[T]` column on a model instance then matches SQLAlchemy's `instance: None` overload of `Mapped.__get__`, so ty types e.g. `ti.dag_id` as `InstrumentedAttribute[str]` instead of `str`. Code type-checked with ty against Airflow's models gets false positives wherever those values are passed on. Declaring `Base` as a value of type `Any` keeps type checkers treating it as `Any`, but as a base of unknown type rather than an explicit `Any` subclass. Runtime behavior is unchanged: the same `generate_base()` call and `__allow_unmapped__` workaround, now without the `TYPE_CHECKING` split. | Checker | `ti.dag_id`, `Base = Any` (before) | `ti.dag_id`, `Base: Any = ...` (after) | |---|---|---| | ty 0.0.93 | `InstrumentedAttribute[str]` | `str` | | mypy | `str` | `str` | | pyright | `str` | `str` | Checks run: `prek run ruff ruff-format` and `prek run mypy-airflow-core` on the changed file both pass; the ty comparison above was run against the patched `airflow-core` sources. related: astral-sh/ty#4850 --- ##### Was generative AI tooling used to co-author this PR? - [X] Yes (please specify the tool below) Generated-by: Claude Code (Opus 5.5) following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
