From: Mike Bayer Date: Mon, 29 May 2023 16:25:42 +0000 (-0400) Subject: base _O around object, not Any X-Git-Tag: rel_2_0_16~16^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0840b0e9ebad83b19845452e3798d85ace17a132;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git base _O around object, not Any There were only a few trivial errors related to this TypeVar being linked to object which were correctable at the source. It's not clear if there were more errors with older versions of mypy and/or the codebase when this was first developed. Change-Id: Ic07ba08e600574b6277ba8540504355e9d7b676c References: #9835 --- diff --git a/lib/sqlalchemy/ext/asyncio/session.py b/lib/sqlalchemy/ext/asyncio/session.py index 6150033025..36b159e58a 100644 --- a/lib/sqlalchemy/ext/asyncio/session.py +++ b/lib/sqlalchemy/ext/asyncio/session.py @@ -10,6 +10,7 @@ import asyncio from typing import Any from typing import Awaitable from typing import Callable +from typing import cast from typing import Dict from typing import Generic from typing import Iterable @@ -581,8 +582,10 @@ class AsyncSession(ReversibleProxy[Session]): """ + # result_obj = self.sync_session.get(entity, ident) + result_obj = await greenlet_spawn( - self.sync_session.get, + cast("Callable[..., _O]", self.sync_session.get), entity, ident, options=options, diff --git a/lib/sqlalchemy/orm/_typing.py b/lib/sqlalchemy/orm/_typing.py index 36dc6ddb9c..cc4233be11 100644 --- a/lib/sqlalchemy/orm/_typing.py +++ b/lib/sqlalchemy/orm/_typing.py @@ -53,18 +53,11 @@ _T = TypeVar("_T", bound=Any) _T_co = TypeVar("_T_co", bound=Any, covariant=True) -# I would have preferred this were bound=object however it seems -# to not travel in all situations when defined in that way. -_O = TypeVar("_O", bound=Any) +_O = TypeVar("_O", bound=object) """The 'ORM mapped object' type. """ -_OO = TypeVar("_OO", bound=object) -"""The 'ORM mapped object, that's definitely object' type. - -""" - if TYPE_CHECKING: _RegistryType = _registry_type diff --git a/lib/sqlalchemy/orm/decl_api.py b/lib/sqlalchemy/orm/decl_api.py index a3a817162f..69efef93b1 100644 --- a/lib/sqlalchemy/orm/decl_api.py +++ b/lib/sqlalchemy/orm/decl_api.py @@ -1604,16 +1604,20 @@ class registry: """ def decorate(cls: Type[_O]) -> Type[_O]: - cls._sa_apply_dc_transforms = { - "init": init, - "repr": repr, - "eq": eq, - "order": order, - "unsafe_hash": unsafe_hash, - "match_args": match_args, - "kw_only": kw_only, - "dataclass_callable": dataclass_callable, - } + setattr( + cls, + "_sa_apply_dc_transforms", + { + "init": init, + "repr": repr, + "eq": eq, + "order": order, + "unsafe_hash": unsafe_hash, + "match_args": match_args, + "kw_only": kw_only, + "dataclass_callable": dataclass_callable, + }, + ) _as_declarative(self, cls, cls.__dict__) return cls diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index 7089395313..8303b1a21a 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -578,7 +578,7 @@ class InstanceState(interfaces.InspectionAttrInfo, Generic[_O]): return self._pending_mutations[key] def __getstate__(self) -> Dict[str, Any]: - state_dict = { + state_dict: Dict[str, Any] = { "instance": self.obj(), "class_": self.class_, "committed_state": self.committed_state, diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index d3e36a4945..a8b78c65a2 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -935,7 +935,7 @@ class AliasedInsp( _weak_entity: weakref.ref[AliasedClass[_O]] """the AliasedClass that refers to this AliasedInsp""" - _target: Union[_O, AliasedClass[_O]] + _target: Union[Type[_O], AliasedClass[_O]] """the thing referred towards by the AliasedClass/AliasedInsp. In the vast majority of cases, this is the mapped class. However