summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-04-17 10:31:48 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-04-17 11:09:03 -0400
commita8b2fbb55c6de302b053b4309c6e53cd7f748448 (patch)
tree51d6deaa1f3b950bab42240385f3ad4bae341f28 /lib
parentc538f810bce57472c8960a0a6c4c61024b00f3ed (diff)
downloadsqlalchemy-a8b2fbb55c6de302b053b4309c6e53cd7f748448.tar.gz
mypy .950 updates
Fixes: #7942 Change-Id: Ice1243e1704e88bb8fa13fb0d1f8e24dcd94bfd4
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/ext/associationproxy.py4
-rw-r--r--lib/sqlalchemy/sql/base.py16
-rw-r--r--lib/sqlalchemy/util/_py_collections.py32
-rw-r--r--lib/sqlalchemy/util/langhelpers.py28
4 files changed, 38 insertions, 42 deletions
diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py
index 2e6c6b422..aca0be683 100644
--- a/lib/sqlalchemy/ext/associationproxy.py
+++ b/lib/sqlalchemy/ext/associationproxy.py
@@ -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()
diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py
index 629e88a32..f7692dbc2 100644
--- a/lib/sqlalchemy/sql/base.py
+++ b/lib/sqlalchemy/sql/base.py
@@ -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)
diff --git a/lib/sqlalchemy/util/_py_collections.py b/lib/sqlalchemy/util/_py_collections.py
index 40f515671..88deac28f 100644
--- a/lib/sqlalchemy/util/_py_collections.py
+++ b/lib/sqlalchemy/util/_py_collections.py
@@ -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
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py
index 4e161c80c..9b3692d59 100644
--- a/lib/sqlalchemy/util/langhelpers.py
+++ b/lib/sqlalchemy/util/langhelpers.py
@@ -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__ = ()