From: Shamil Abdulaev Date: Thu, 23 Apr 2026 17:09:07 +0000 (-0400) Subject: Remove unused TypeVars and compat import from typing modules X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=15f1d6dce6870c6ca9b5ad72d79e5a3cdc3a47bd;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Remove unused TypeVars and compat import from typing modules ## Summary Removes 4 dead symbols from SQLAlchemy's typing modules. Each symbol has **zero references** across `lib/`, `test/`, `doc/`, `tools/`, and `examples/` — verified by grep for direct references, string forward references, and `getattr`-style dynamic access. ## Changes **`lib/sqlalchemy/util/typing.py`** - Remove `from . import compat` — unused module import; the only occurrence of `compat` in the file is in a code comment on line 221 - Remove `_KT_co = TypeVar("_KT_co", covariant=True)` — unused TypeVar - Remove `_KT_contra = TypeVar("_KT_contra", contravariant=True)` — unused TypeVar **`lib/sqlalchemy/orm/_typing.py`** - Remove `_T_co = TypeVar("_T_co", bound=Any, covariant=True)` — orphaned; `orm.base` imports `_T_co` from `sql._typing` instead, and other orm modules (`interfaces.py`, `attributes.py`) define their own local `_T_co` Total: **-7 lines**, no additions. ## Verification For each removed symbol: | Symbol | Repo-wide grep result | |---|---| | `compat` (in `util/typing.py`) | 0 references to `compat.` or `util.typing.compat` outside the import itself | | `_KT_co` | 1 hit total (the removed definition line) | | `_KT_contra` | 1 hit total (the removed definition line) | | `_T_co` (in `orm/_typing.py`) | No `from sqlalchemy.orm._typing import _T_co` or `from ..orm._typing import _T_co` anywhere; all consumers import from `sql._typing` or define locally | Additionally checked: - No `__all__` references - No string forward references (e.g. `"_KT_co"`) - No `getattr(..., "_T_co")` or similar dynamic access - No re-exports via `util/__init__.py` or any other module - `test/base/test_typing_utils.py` (which imports `util.typing as sa_typing`) does not touch any of these names ## Test plan - [x] `pre-commit` hooks pass (black, zimports, flake8) - [x] `import sqlalchemy`, `sqlalchemy.orm`, `sqlalchemy.util.typing`, `sqlalchemy.orm._typing`, `sqlalchemy.sql._typing`, `sqlalchemy.dialects._typing` — all import cleanly - [x] Broad import smoke test: `Mapped`, `DeclarativeBase`, `relationship`, `Session`, `Mapper`, `mapped_column`, `Column`, `select`, `create_engine`, `MetaData`, `QueuePool`, `hybrid_property`, `association_proxy` — all import cleanly - [x] Full `tox` / test suite — would appreciate CI confirmation ## Not included (intentionally) - `LiteralString` re-export in `util/typing.py:54` — has 0 in-tree consumers but is an explicit `as X as X` public re-export; kept for API stability - `is_origin_of` rename to `_is_origin_of` — used only internally by `is_union`, but renaming is a minor breaking change not worth the churn Closes: #13244 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13244 Pull-request-sha: 8242f373685c35264ffd52071345a6dfce855277 Change-Id: Iae389447ac46599df27ab9776ff5ad19dfef4e2c --- diff --git a/lib/sqlalchemy/orm/_typing.py b/lib/sqlalchemy/orm/_typing.py index 2e8c49320a..ab9518beb4 100644 --- a/lib/sqlalchemy/orm/_typing.py +++ b/lib/sqlalchemy/orm/_typing.py @@ -50,9 +50,6 @@ if TYPE_CHECKING: _T = TypeVar("_T", bound=Any) - -_T_co = TypeVar("_T_co", bound=Any, covariant=True) - _O = TypeVar("_O", bound=object) """The 'ORM mapped object' type. diff --git a/lib/sqlalchemy/util/typing.py b/lib/sqlalchemy/util/typing.py index 01bf0a7b3a..ef5b171b0a 100644 --- a/lib/sqlalchemy/util/typing.py +++ b/lib/sqlalchemy/util/typing.py @@ -39,8 +39,6 @@ from typing import Union import typing_extensions -from . import compat - if True: # zimports removes the tailing comments from typing_extensions import ( dataclass_transform as dataclass_transform, # 3.11, @@ -57,8 +55,6 @@ if True: # zimports removes the tailing comments _T = TypeVar("_T", bound=Any) _KT = TypeVar("_KT") -_KT_co = TypeVar("_KT_co", covariant=True) -_KT_contra = TypeVar("_KT_contra", contravariant=True) _VT = TypeVar("_VT") _VT_co = TypeVar("_VT_co", covariant=True)