From: Mike Bayer Date: Fri, 12 Sep 2025 23:01:31 +0000 (-0400) Subject: do the mypy dance X-Git-Tag: rel_2_0_44~29 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4b3cf12b39bd999d131fc39cf65f8252cf135e7d;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 (cherry picked from commit e7ff28e21e063b13cc6bfe4ca69e108bffc03c4b) --- diff --git a/lib/sqlalchemy/dialects/postgresql/array.py b/lib/sqlalchemy/dialects/postgresql/array.py index 7339d5c7d8..41c0a9147e 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( @@ -357,7 +358,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 d4ecbdac98..89e503c256 100644 --- a/lib/sqlalchemy/ext/asyncio/engine.py +++ b/lib/sqlalchemy/ext/asyncio/engine.py @@ -186,7 +186,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, @@ -994,7 +995,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 c116b05756..2c812f9bab 100644 --- a/lib/sqlalchemy/orm/events.py +++ b/lib/sqlalchemy/orm/events.py @@ -735,7 +735,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) @@ -1524,7 +1525,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 fe9c8e96e8..fac50b5808 100644 --- a/lib/sqlalchemy/orm/writeonly.py +++ b/lib/sqlalchemy/orm/writeonly.py @@ -411,7 +411,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( @@ -422,7 +422,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 7cb2265ea4..d9cf3c98f9 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -2995,8 +2995,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`. @@ -3007,7 +3007,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 0f1e588bd9..9669cc7d77 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]