]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Typing updates to fix errors found by mypy 1.7
authorFederico Caselli <cfederico87@gmail.com>
Sat, 11 Nov 2023 15:26:57 +0000 (16:26 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Sat, 11 Nov 2023 17:11:03 +0000 (18:11 +0100)
Change-Id: I02046a72df88a82c8bc6e40b41f9d5b0d01a163e

lib/sqlalchemy/engine/cursor.py
lib/sqlalchemy/engine/result.py
lib/sqlalchemy/engine/row.py
lib/sqlalchemy/orm/decl_base.py
lib/sqlalchemy/orm/interfaces.py
lib/sqlalchemy/util/_py_collections.py
lib/sqlalchemy/util/compat.py

index 45af49afccb877f14644d61fe18b2d04e9c4b479..ff6e311a743ac4d7e0203409a2a54f609c1fcb31 100644 (file)
@@ -120,7 +120,7 @@ _CursorKeyMapRecType = Tuple[
     List[Any],  # MD_OBJECTS
     str,  # MD_LOOKUP_KEY
     str,  # MD_RENDERED_NAME
-    Optional["_ResultProcessorType"],  # MD_PROCESSOR
+    Optional["_ResultProcessorType[Any]"],  # MD_PROCESSOR
     Optional[str],  # MD_UNTRANSLATED
 ]
 
@@ -134,7 +134,7 @@ _NonAmbigCursorKeyMapRecType = Tuple[
     List[Any],
     str,
     str,
-    Optional["_ResultProcessorType"],
+    Optional["_ResultProcessorType[Any]"],
     str,
 ]
 
@@ -1438,6 +1438,7 @@ class CursorResult(Result[_T]):
 
             metadata = self._init_metadata(context, cursor_description)
 
+            _make_row: Any
             _make_row = functools.partial(
                 Row,
                 metadata,
index 132ae88b660ebdd596ef396cd679c6a2760f0796..acbe6f0923632f5e3f3b44600206a4e5658fadd5 100644 (file)
@@ -64,7 +64,7 @@ _KeyMapRecType = Any
 _KeyMapType = Mapping[_KeyType, _KeyMapRecType]
 
 
-_RowData = Union[Row, RowMapping, Any]
+_RowData = Union[Row[Any], RowMapping, Any]
 """A generic form of "row" that accommodates for the different kinds of
 "rows" that different result objects return, including row, row mapping, and
 scalar values"""
@@ -82,7 +82,7 @@ across all the result types
 
 """
 
-_InterimSupportsScalarsRowType = Union[Row, Any]
+_InterimSupportsScalarsRowType = Union[Row[Any], Any]
 
 _ProcessorsType = Sequence[Optional["_ResultProcessorType[Any]"]]
 _TupleGetterType = Callable[[Sequence[Any]], Sequence[Any]]
index 9017537ab09f4ce0a88077a55bc6c055d2d5c776..d2bb2e4c9a6a716a1420bf39fda7c3b35c6ade63 100644 (file)
@@ -296,8 +296,8 @@ class ROMappingView(ABC):
     def __init__(
         self, mapping: Mapping["_KeyType", Any], items: Sequence[Any]
     ):
-        self._mapping = mapping
-        self._items = items
+        self._mapping = mapping  # type: ignore[misc]
+        self._items = items  # type: ignore[misc]
 
     def __len__(self) -> int:
         return len(self._items)
@@ -321,11 +321,11 @@ class ROMappingView(ABC):
 class ROMappingKeysValuesView(
     ROMappingView, typing.KeysView["_KeyType"], typing.ValuesView[Any]
 ):
-    __slots__ = ("_items",)
+    __slots__ = ("_items",)  # mapping slot is provided by KeysView
 
 
 class ROMappingItemsView(ROMappingView, typing.ItemsView["_KeyType", Any]):
-    __slots__ = ("_items",)
+    __slots__ = ("_items",)  # mapping slot is provided by ItemsView
 
 
 class RowMapping(BaseRow, typing.Mapping["_KeyType", Any]):
index d5ef3db470ac1d03b7830c93d583253868520474..0037379bd5f36e2631e3245e4038f5b43488c49b 100644 (file)
@@ -1130,9 +1130,9 @@ class _ClassScanMapperConfig(_MapperConfig):
         defaults = {}
         for item in field_list:
             if len(item) == 2:
-                name, tp = item  # type: ignore
+                name, tp = item
             elif len(item) == 3:
-                name, tp, spec = item  # type: ignore
+                name, tp, spec = item
                 defaults[name] = spec
             else:
                 assert False
index a118b2aa85467cabc4fba0e5f79c5453fab2ed4f..fed07334fb588020b4a70fc212c2dc2b8afb71fb 100644 (file)
@@ -754,7 +754,7 @@ class PropComparator(SQLORMOperations[_T_co], Generic[_T_co], ColumnOperators):
         self._adapt_to_entity = adapt_to_entity
 
     @util.non_memoized_property
-    def property(self) -> MapperProperty[_T]:
+    def property(self) -> MapperProperty[_T_co]:
         """Return the :class:`.MapperProperty` associated with this
         :class:`.PropComparator`.
 
@@ -784,7 +784,7 @@ class PropComparator(SQLORMOperations[_T_co], Generic[_T_co], ColumnOperators):
 
     def adapt_to_entity(
         self, adapt_to_entity: AliasedInsp[Any]
-    ) -> PropComparator[_T]:
+    ) -> PropComparator[_T_co]:
         """Return a copy of this PropComparator which will use the given
         :class:`.AliasedInsp` to produce corresponding expressions.
         """
@@ -846,7 +846,7 @@ class PropComparator(SQLORMOperations[_T_co], Generic[_T_co], ColumnOperators):
         ) -> ColumnElement[Any]:
             ...
 
-    def of_type(self, class_: _EntityType[Any]) -> PropComparator[_T]:
+    def of_type(self, class_: _EntityType[Any]) -> PropComparator[_T_co]:
         r"""Redefine this object in terms of a polymorphic subclass,
         :func:`_orm.with_polymorphic` construct, or :func:`_orm.aliased`
         construct.
index 4f52d3bce67615edddd428fa35b26460ef7bc4da..7dba5092bcf0b44125ff7b83422cd9027e3a6ab3 100644 (file)
@@ -148,12 +148,16 @@ class immutabledict(ImmutableDictBase[_KT, _VT]):
     def __or__(  # type: ignore[override]
         self, __value: Mapping[_KT, _VT]
     ) -> immutabledict[_KT, _VT]:
-        return immutabledict(super().__or__(__value))
+        return immutabledict(
+            super().__or__(__value),  # type: ignore[call-overload]
+        )
 
     def __ror__(  # type: ignore[override]
         self, __value: Mapping[_KT, _VT]
     ) -> immutabledict[_KT, _VT]:
-        return immutabledict(super().__ror__(__value))
+        return immutabledict(
+            super().__ror__(__value),  # type: ignore[call-overload]
+        )
 
 
 class OrderedSet(Set[_T]):
index a0dbc9104aa502a3685afe989f9edd9c7f77b94f..7cbaa24069f57afd4cdca5b57c0ca2f44f3707a9 100644 (file)
@@ -166,7 +166,7 @@ else:
 
 def importlib_metadata_get(group):
     ep = importlib_metadata.entry_points()
-    if not typing.TYPE_CHECKING and hasattr(ep, "select"):
+    if hasattr(ep, "select"):
         return ep.select(group=group)
     else:
         return ep.get(group, ())