]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
mypy .950 updates
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 17 Apr 2022 14:31:48 +0000 (10:31 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 17 Apr 2022 15:09:03 +0000 (11:09 -0400)
Fixes: #7942
Change-Id: Ice1243e1704e88bb8fa13fb0d1f8e24dcd94bfd4

lib/sqlalchemy/ext/associationproxy.py
lib/sqlalchemy/sql/base.py
lib/sqlalchemy/util/_py_collections.py
lib/sqlalchemy/util/langhelpers.py

index 2e6c6b422a1c0a932626e78dc3707d191f9d1e0a..aca0be683743aca77d28751551519faf87bcb64e 100644 (file)
@@ -1804,7 +1804,7 @@ class _AssociationSet(_AssociationSingleItem[_T], MutableSet[_T]):
         for member in removals:
             remover(member)
 
-    def __ior__(
+    def __ior__(  # type: ignore
         self: Self, other: AbstractSet[_S]
     ) -> MutableSet[Union[_T, _S]]:
         if not collections._set_binops_check_strict(self, other):
@@ -1887,7 +1887,7 @@ class _AssociationSet(_AssociationSingleItem[_T], MutableSet[_T]):
         for value in add:
             self.add(value)
 
-    def __ixor__(self, other: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]:
+    def __ixor__(self, other: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]:  # type: ignore  # noqa: E501
         if not collections._set_binops_check_strict(self, other):
             raise NotImplementedError()
 
index 629e88a32637dc62a1e931c49895dfb2263ac2af..f7692dbc2ac51a8450e438ad08fbb6813403d246 100644 (file)
@@ -229,9 +229,9 @@ def _generative(fn: _Fn) -> _Fn:
         assert x is self, "generative methods must return self"
         return self
 
-    decorated = _generative(fn)  # type: ignore
+    decorated = _generative(fn)
     decorated.non_generative = fn  # type: ignore
-    return decorated  # type: ignore
+    return decorated
 
 
 def _exclusive_against(*names: str, **kw: Any) -> Callable[[_Fn], _Fn]:
@@ -1749,8 +1749,10 @@ class DedupeColumnCollection(ColumnCollection[str, _NAMEDCOL]):
                 self._index[k] = col
                 self._collection.append((k, col))
         self._colset.update(c for (k, c) in self._collection)
+
+        # https://github.com/python/mypy/issues/12610
         self._index.update(
-            (idx, c) for idx, (k, c) in enumerate(self._collection)
+            (idx, c) for idx, (k, c) in enumerate(self._collection)  # type: ignore  # noqa: E501
         )
         for col in replace_col:
             self.replace(col)
@@ -1769,8 +1771,10 @@ class DedupeColumnCollection(ColumnCollection[str, _NAMEDCOL]):
         self._collection[:] = [
             (k, c) for (k, c) in self._collection if c is not column
         ]
+
+        # https://github.com/python/mypy/issues/12610
         self._index.update(
-            {idx: col for idx, (k, col) in enumerate(self._collection)}
+            {idx: col for idx, (k, col) in enumerate(self._collection)}  # type: ignore  # noqa: E501
         )
         # delete higher index
         del self._index[len(self._collection)]
@@ -1822,8 +1826,10 @@ class DedupeColumnCollection(ColumnCollection[str, _NAMEDCOL]):
         self._collection[:] = new_cols
 
         self._index.clear()
+
+        # https://github.com/python/mypy/issues/12610
         self._index.update(
-            {idx: col for idx, (k, col) in enumerate(self._collection)}
+            {idx: col for idx, (k, col) in enumerate(self._collection)}  # type: ignore  # noqa: E501
         )
         self._index.update(self._collection)
 
index 40f51567184e137b31d990354be3631fbba610f5..88deac28f8c8abcb8ebf5b25d373bff47704aba5 100644 (file)
@@ -175,7 +175,7 @@ class OrderedSet(Set[_T]):
     def __iter__(self) -> Iterator[_T]:
         return iter(self._list)
 
-    def __add__(self, other: Iterator[_T]) -> "OrderedSet[_T]":
+    def __add__(self, other: Iterator[_T]) -> OrderedSet[_T]:
         return self.union(other)
 
     def __repr__(self) -> str:
@@ -190,50 +190,50 @@ class OrderedSet(Set[_T]):
                     self._list.append(e)
                     super().add(e)
 
-    def __ior__(self, other: AbstractSet[_S]) -> "OrderedSet[Union[_T, _S]]":
+    def __ior__(self, other: AbstractSet[_S]) -> OrderedSet[Union[_T, _S]]:
         self.update(other)  # type: ignore
         return self  # type: ignore
 
-    def union(self, *other: Iterable[_S]) -> "OrderedSet[Union[_T, _S]]":
-        result: "OrderedSet[Union[_T, _S]]" = self.__class__(self)  # type: ignore  # noqa: E501
+    def union(self, *other: Iterable[_S]) -> OrderedSet[Union[_T, _S]]:
+        result: OrderedSet[Union[_T, _S]] = self.__class__(self)  # type: ignore  # noqa: E501
         for o in other:
             result.update(o)
         return result
 
-    def __or__(self, other: AbstractSet[_S]) -> "OrderedSet[Union[_T, _S]]":
+    def __or__(self, other: AbstractSet[_S]) -> OrderedSet[Union[_T, _S]]:
         return self.union(other)
 
-    def intersection(self, *other: Iterable[Any]) -> "OrderedSet[_T]":
+    def intersection(self, *other: Iterable[Any]) -> OrderedSet[_T]:
         other_set: Set[Any] = set()
         other_set.update(*other)
         return self.__class__(a for a in self if a in other_set)
 
-    def __and__(self, other: AbstractSet[object]) -> "OrderedSet[_T]":
+    def __and__(self, other: AbstractSet[object]) -> OrderedSet[_T]:
         return self.intersection(other)
 
-    def symmetric_difference(self, other: Iterable[_T]) -> "OrderedSet[_T]":
+    def symmetric_difference(self, other: Iterable[_T]) -> OrderedSet[_T]:
         other_set = other if isinstance(other, set) else set(other)
         result = self.__class__(a for a in self if a not in other_set)
         result.update(a for a in other if a not in self)
         return result
 
-    def __xor__(self, other: AbstractSet[_S]) -> "OrderedSet[Union[_T, _S]]":
-        return cast("OrderedSet[Union[_T, _S]]", self).symmetric_difference(
+    def __xor__(self, other: AbstractSet[_S]) -> OrderedSet[Union[_T, _S]]:
+        return cast(OrderedSet[Union[_T, _S]], self).symmetric_difference(
             other
         )
 
-    def difference(self, *other: Iterable[Any]) -> "OrderedSet[_T]":
+    def difference(self, *other: Iterable[Any]) -> OrderedSet[_T]:
         other_set = super().difference(*other)
         return self.__class__(a for a in self._list if a in other_set)
 
-    def __sub__(self, other: AbstractSet[Optional[_T]]) -> "OrderedSet[_T]":
+    def __sub__(self, other: AbstractSet[Optional[_T]]) -> OrderedSet[_T]:
         return self.difference(other)
 
     def intersection_update(self, *other: Iterable[Any]) -> None:
         super().intersection_update(*other)
         self._list = [a for a in self._list if a in self]
 
-    def __iand__(self, other: AbstractSet[object]) -> "OrderedSet[_T]":
+    def __iand__(self, other: AbstractSet[object]) -> OrderedSet[_T]:
         self.intersection_update(other)
         return self
 
@@ -242,15 +242,15 @@ class OrderedSet(Set[_T]):
         self._list = [a for a in self._list if a in self]
         self._list += [a for a in other if a in self]
 
-    def __ixor__(self, other: AbstractSet[_S]) -> "OrderedSet[Union[_T, _S]]":
+    def __ixor__(self, other: AbstractSet[_S]) -> OrderedSet[Union[_T, _S]]:
         self.symmetric_difference_update(other)
-        return cast("OrderedSet[Union[_T, _S]]", self)
+        return cast(OrderedSet[Union[_T, _S]], self)
 
     def difference_update(self, *other: Iterable[Any]) -> None:
         super().difference_update(*other)
         self._list = [a for a in self._list if a in self]
 
-    def __isub__(self, other: AbstractSet[Optional[_T]]) -> "OrderedSet[_T]":
+    def __isub__(self, other: AbstractSet[Optional[_T]]) -> OrderedSet[_T]:  # type: ignore  # noqa: E501
         self.difference_update(other)
         return self
 
index 4e161c80c2bf3035198cb628f804b4d27a181709..9b3692d595a295efe7b7b46466e8c9e620406eed 100644 (file)
@@ -23,7 +23,6 @@ import sys
 import textwrap
 import threading
 import types
-import typing
 from typing import Any
 from typing import Callable
 from typing import cast
@@ -47,8 +46,8 @@ import warnings
 
 from . import _collections
 from . import compat
-from . import typing as compat_typing
 from ._has_cy import HAS_CYEXTENSION
+from .typing import Literal
 from .. import exc
 
 _T = TypeVar("_T")
@@ -237,18 +236,13 @@ def map_bits(fn: Callable[[int], Any], n: int) -> Iterator[Any]:
         n ^= b
 
 
-_Fn = typing.TypeVar("_Fn", bound=typing.Callable[..., Any])
-_Args = compat_typing.ParamSpec("_Args")
+_Fn = TypeVar("_Fn", bound="Callable[..., Any]")
 
 
-def decorator(
-    target: typing.Callable[  # type: ignore
-        compat_typing.Concatenate[_Fn, _Args], typing.Any
-    ]
-) -> _Fn:
+def decorator(target: Callable[..., Any]) -> Callable[[_Fn], _Fn]:
     """A signature-matching decorator factory."""
 
-    def decorate(fn: typing.Callable[..., Any]) -> typing.Callable[..., Any]:
+    def decorate(fn: _Fn) -> _Fn:
         if not inspect.isfunction(fn) and not inspect.ismethod(fn):
             raise Exception("not a decoratable function")
 
@@ -282,12 +276,10 @@ def %(name)s%(grouped_args)s:
         )
         decorated.__defaults__ = getattr(fn, "__func__", fn).__defaults__
 
-        # claims to be fixed?
-        # https://github.com/python/mypy/issues/11896
         decorated.__wrapped__ = fn  # type: ignore
-        return update_wrapper(decorated, fn)
+        return cast(_Fn, update_wrapper(decorated, fn))
 
-    return typing.cast(_Fn, update_wrapper(decorate, target))
+    return update_wrapper(decorate, target)
 
 
 def _update_argspec_defaults_into_env(spec, env):
@@ -321,8 +313,6 @@ def _exec_code_in_env(
 _PF = TypeVar("_PF")
 _TE = TypeVar("_TE")
 
-_P = compat_typing.ParamSpec("_P")
-
 
 class PluginLoader:
     def __init__(
@@ -389,7 +379,7 @@ def get_cls_kwargs(
     cls: type,
     *,
     _set: Optional[Set[str]] = None,
-    raiseerr: compat_typing.Literal[True] = ...,
+    raiseerr: Literal[True] = ...,
 ) -> Set[str]:
     ...
 
@@ -1082,7 +1072,7 @@ class generic_fn_descriptor(Generic[_T_co]):
     def __get__(self: _GFD, obj: Any, cls: Any) -> Union[_GFD, _T_co]:
         raise NotImplementedError()
 
-    if typing.TYPE_CHECKING:
+    if TYPE_CHECKING:
 
         def __set__(self, instance: Any, value: Any) -> None:
             ...
@@ -1192,7 +1182,7 @@ class HasMemoized:
 
     """
 
-    if not typing.TYPE_CHECKING:
+    if not TYPE_CHECKING:
         # support classes that want to have __slots__ with an explicit
         # slot for __dict__.  not sure if that requires base __slots__ here.
         __slots__ = ()