From: Mike Bayer Date: Fri, 12 Sep 2025 23:01:31 +0000 (-0400) Subject: do the mypy dance X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e7ff28e21e063b13cc6bfe4ca69e108bffc03c4b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git do the mypy dance version 1.18.1. lots of i have no idea situations. just add ignores, seems pretty pointless Change-Id: Ieb1466df3f45fa6b8d11ccd36c7164645740ba35 --- diff --git a/lib/sqlalchemy/dialects/postgresql/array.py b/lib/sqlalchemy/dialects/postgresql/array.py index 45b53f0d04..a3ac4d8fd4 100644 --- a/lib/sqlalchemy/dialects/postgresql/array.py +++ b/lib/sqlalchemy/dialects/postgresql/array.py @@ -44,6 +44,7 @@ if TYPE_CHECKING: _T = TypeVar("_T", bound=typing_Any) +_CT = TypeVar("_CT", bound=typing_Any) def Any( @@ -355,7 +356,7 @@ class ARRAY(sqltypes.ARRAY[_T]): self.dimensions = dimensions self.zero_indexes = zero_indexes - class Comparator(sqltypes.ARRAY.Comparator[_T]): + class Comparator(sqltypes.ARRAY.Comparator[_CT]): """Define comparison operations for :class:`_types.ARRAY`. Note that these operations are in addition to those provided diff --git a/lib/sqlalchemy/ext/asyncio/engine.py b/lib/sqlalchemy/ext/asyncio/engine.py index 5f5ec6cf35..dfc727a302 100644 --- a/lib/sqlalchemy/ext/asyncio/engine.py +++ b/lib/sqlalchemy/ext/asyncio/engine.py @@ -189,7 +189,8 @@ class AsyncConnectable: "default_isolation_level", ], ) -class AsyncConnection( +# "Class has incompatible disjoint bases" - no idea +class AsyncConnection( # type:ignore[misc] ProxyComparable[Connection], StartableContext["AsyncConnection"], AsyncConnectable, @@ -998,7 +999,8 @@ class AsyncConnection( ], attributes=["url", "pool", "dialect", "engine", "name", "driver", "echo"], ) -class AsyncEngine(ProxyComparable[Engine], AsyncConnectable): +# "Class has incompatible disjoint bases" - no idea +class AsyncEngine(ProxyComparable[Engine], AsyncConnectable): # type: ignore[misc] # noqa:E501 """An asyncio proxy for a :class:`_engine.Engine`. :class:`_asyncio.AsyncEngine` is acquired using the diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py index b915cdfec8..9ef1bc154e 100644 --- a/lib/sqlalchemy/orm/events.py +++ b/lib/sqlalchemy/orm/events.py @@ -713,7 +713,8 @@ class _InstanceEventsHold(_EventsHold[_ET]): def resolve(self, class_: Type[_O]) -> Optional[ClassManager[_O]]: return instrumentation.opt_manager_of_class(class_) - class HoldInstanceEvents(_EventsHold.HoldEvents[_ET], InstanceEvents): # type: ignore [misc] # noqa: E501 + # this fails on pyright if you use Any. Fails on mypy if you use _ET + class HoldInstanceEvents(_EventsHold.HoldEvents[_ET], InstanceEvents): # type: ignore[valid-type,misc] # noqa: E501 pass dispatch = event.dispatcher(HoldInstanceEvents) @@ -1502,7 +1503,8 @@ class _MapperEventsHold(_EventsHold[_ET]): ) -> Optional[Mapper[_T]]: return _mapper_or_none(class_) - class HoldMapperEvents(_EventsHold.HoldEvents[_ET], MapperEvents): # type: ignore [misc] # noqa: E501 + # this fails on pyright if you use Any. Fails on mypy if you use _ET + class HoldMapperEvents(_EventsHold.HoldEvents[_ET], MapperEvents): # type: ignore[valid-type,misc] # noqa: E501 pass dispatch = event.dispatcher(HoldMapperEvents) diff --git a/lib/sqlalchemy/orm/writeonly.py b/lib/sqlalchemy/orm/writeonly.py index 1343a74bfe..b5aaf16e8c 100644 --- a/lib/sqlalchemy/orm/writeonly.py +++ b/lib/sqlalchemy/orm/writeonly.py @@ -423,7 +423,7 @@ class _WriteOnlyAttributeImpl( initiator: Optional[AttributeEventToken], passive: PassiveFlag = PassiveFlag.PASSIVE_NO_FETCH, ) -> None: - if initiator is not self: + if initiator is not self: # type: ignore[comparison-overlap] self.fire_append_event(state, dict_, value, initiator) def remove( @@ -434,7 +434,7 @@ class _WriteOnlyAttributeImpl( initiator: Optional[AttributeEventToken], passive: PassiveFlag = PassiveFlag.PASSIVE_NO_FETCH, ) -> None: - if initiator is not self: + if initiator is not self: # type: ignore[comparison-overlap] self.fire_remove_event(state, dict_, value, initiator) def pop( diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 916e6444e5..0261d7a26b 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -3050,8 +3050,8 @@ class ARRAY( self.zero_indexes = zero_indexes class Comparator( - Indexable.Comparator[Sequence[_T]], - Concatenable.Comparator[Sequence[_T]], + Indexable.Comparator[Sequence[_CT]], + Concatenable.Comparator[Sequence[_CT]], ): """Define comparison operations for :class:`_types.ARRAY`. @@ -3062,7 +3062,7 @@ class ARRAY( __slots__ = () - type: ARRAY[_T] + type: ARRAY[_CT] @overload def _setup_getitem( diff --git a/test/typing/plain_files/dialects/postgresql/pg_stuff.py b/test/typing/plain_files/dialects/postgresql/pg_stuff.py index 4a50a9e42c..20785bc2cb 100644 --- a/test/typing/plain_files/dialects/postgresql/pg_stuff.py +++ b/test/typing/plain_files/dialects/postgresql/pg_stuff.py @@ -116,7 +116,7 @@ array_of_ints = array([0], type_=Integer) # EXPECTED_TYPE: array[int] reveal_type(array_of_ints) -# EXPECTED_MYPY: Cannot infer type argument 1 of "array" +# EXPECTED_MYPY_RE: Cannot infer .* of "array" array([0], type_=Text) # EXPECTED_TYPE: ARRAY[str]