]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
base _O around object, not Any
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 29 May 2023 16:25:42 +0000 (12:25 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 29 May 2023 16:25:42 +0000 (12:25 -0400)
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

lib/sqlalchemy/ext/asyncio/session.py
lib/sqlalchemy/orm/_typing.py
lib/sqlalchemy/orm/decl_api.py
lib/sqlalchemy/orm/state.py
lib/sqlalchemy/orm/util.py

index 61500330256f1b487eabc35d8fa9e4cc6b615d1d..36b159e58a20bf4fb15c30f0030305a7d30ae838 100644 (file)
@@ -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,
index 36dc6ddb9cecc5f1bb251dc059767145e76c9a7f..cc4233be1113f469bfa2329056d1a652f66ca0a6 100644 (file)
@@ -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
index a3a817162fc807e4e587709ec098ed6f3021bff6..69efef93b1576530c2b8c9d9e6720399e9f5276d 100644 (file)
@@ -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
 
index 7089395313276f254961f6e0ee92fc181bd6b2b3..8303b1a21a9f0e1bc5ccc8e7145ec5bb1375fe4b 100644 (file)
@@ -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,
index d3e36a4945ed30c70d3eac998ad1193517de17c5..a8b78c65a2f004c592199b603b0e577997417f62 100644 (file)
@@ -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