]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
update for mypy 1.1.1
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 8 Mar 2023 17:14:01 +0000 (12:14 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 8 Mar 2023 18:52:41 +0000 (13:52 -0500)
looks like mypy 1.1.1 slipped in after the last jenkins pep484 build
for SQLAlchemy.  update for its new issues.

Change-Id: Ifca967a75d5e592c04b0138aeda9b646067fe59b

doc/build/changelog/unreleased_20/mypy_111.rst [new file with mode: 0644]
lib/sqlalchemy/ext/mutable.py
lib/sqlalchemy/orm/decl_api.py
lib/sqlalchemy/util/_collections.py
lib/sqlalchemy/util/_py_collections.py
tox.ini

diff --git a/doc/build/changelog/unreleased_20/mypy_111.rst b/doc/build/changelog/unreleased_20/mypy_111.rst
new file mode 100644 (file)
index 0000000..22301ef
--- /dev/null
@@ -0,0 +1,4 @@
+.. change::
+    :tags: bug, typing
+
+    Fixed issues to allow typing tests to pass under Mypy 1.1.1.
index 940d62b0aab62f486d1b65b3d4a5a0c63edf4d90..0dd3215595e8976ef63540b0596f429b3e700148 100644 (file)
@@ -784,15 +784,19 @@ class MutableDict(Mutable, Dict[_KT, _VT]):
 
     if TYPE_CHECKING:
 
+        # from https://github.com/python/mypy/issues/14858
+
         @overload
-        def setdefault(self, key: _KT) -> _VT | None:
+        def setdefault(
+            self: MutableDict[_KT, Optional[_T]], key: _KT, value: None = None
+        ) -> Optional[_T]:
             ...
 
         @overload
         def setdefault(self, key: _KT, value: _VT) -> _VT:
             ...
 
-        def setdefault(self, key: _KT, value: _VT | None = None) -> _VT | None:
+        def setdefault(self, key: _KT, value: object = None) -> object:
             ...
 
     else:
index f332d296460e347f625fc6496c7029df3db23a71..60d2fbc2b76ed5b26d72b01a5fa5ae1084164ff2 100644 (file)
@@ -150,11 +150,11 @@ class DeclarativeAttributeIntercept(
 
 @compat_typing.dataclass_transform(
     field_specifiers=(
-        MappedColumn[Any],
-        RelationshipProperty[Any],
-        Composite[Any],
-        ColumnProperty[Any],
-        Synonym[Any],
+        MappedColumn,
+        RelationshipProperty,
+        Composite,
+        ColumnProperty,
+        Synonym,
         mapped_column,
         relationship,
         composite,
@@ -1546,11 +1546,11 @@ class registry:
 
     @compat_typing.dataclass_transform(
         field_specifiers=(
-            MappedColumn[Any],
-            RelationshipProperty[Any],
-            Composite[Any],
-            ColumnProperty[Any],
-            Synonym[Any],
+            MappedColumn,
+            RelationshipProperty,
+            Composite,
+            ColumnProperty,
+            Synonym,
             mapped_column,
             relationship,
             composite,
index b1e3fd23f01d5fa0fe3239cdfab5858f1154278a..af117dc92c697052ccb9e892e486696f85defe4c 100644 (file)
@@ -143,7 +143,7 @@ class FacadeDict(ImmutableDictBase[_KT, _VT]):
     """A dictionary that is not publicly mutable."""
 
     def __new__(cls, *args: Any) -> FacadeDict[Any, Any]:
-        new = dict.__new__(cls)
+        new = ImmutableDictBase.__new__(cls)
         return new
 
     def copy(self) -> NoReturn:
index 048825f606548264bc1d913ab7dde3bf726b169d..8810800c42ab876c1237b794c4bb23cc0a48c309 100644 (file)
@@ -23,9 +23,12 @@ from typing import NoReturn
 from typing import Optional
 from typing import Set
 from typing import Tuple
+from typing import TYPE_CHECKING
 from typing import TypeVar
 from typing import Union
 
+from ..util.typing import Self
+
 _T = TypeVar("_T", bound=Any)
 _S = TypeVar("_S", bound=Any)
 _KT = TypeVar("_KT", bound=Any)
@@ -54,6 +57,14 @@ class ReadOnlyContainer:
 
 
 class ImmutableDictBase(ReadOnlyContainer, Dict[_KT, _VT]):
+    if TYPE_CHECKING:
+
+        def __new__(cls, *args: Any) -> Self:
+            ...
+
+        def __init__(cls, *args: Any):
+            ...
+
     def _readonly(self, *arg: Any, **kw: Any) -> NoReturn:
         self._immutable()
 
@@ -75,7 +86,7 @@ class ImmutableDictBase(ReadOnlyContainer, Dict[_KT, _VT]):
 
 class immutabledict(ImmutableDictBase[_KT, _VT]):
     def __new__(cls, *args):
-        new = dict.__new__(cls)
+        new = ImmutableDictBase.__new__(cls)
         dict.__init__(new, *args)
         return new
 
@@ -93,7 +104,7 @@ class immutabledict(ImmutableDictBase[_KT, _VT]):
         if not __d:
             return self
 
-        new = dict.__new__(self.__class__)
+        new = ImmutableDictBase.__new__(self.__class__)
         dict.__init__(new, self)
         dict.update(new, __d)  # type: ignore
         return new
@@ -105,7 +116,7 @@ class immutabledict(ImmutableDictBase[_KT, _VT]):
         if not __d and not kw:
             return self
 
-        new = dict.__new__(self.__class__)
+        new = ImmutableDictBase.__new__(self.__class__)
         dict.__init__(new, self)
         if __d:
             dict.update(new, __d)  # type: ignore
@@ -119,7 +130,7 @@ class immutabledict(ImmutableDictBase[_KT, _VT]):
         for d in dicts:
             if d:
                 if new is None:
-                    new = dict.__new__(self.__class__)
+                    new = ImmutableDictBase.__new__(self.__class__)
                     dict.__init__(new, self)
                 dict.update(new, d)  # type: ignore
         if new is None:
diff --git a/tox.ini b/tox.ini
index dad8a0d2a57c5315a454740fbf228e642fef785b..ca1e46d6a7a7e5d06edaf44f69529a8fa7a44d10 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -154,7 +154,7 @@ commands=
 deps=
      greenlet != 0.4.17
      importlib_metadata; python_version < '3.8'
-     mypy >= 1.0.0
+     mypy >= 1.1.1
 commands =
     mypy  {env:MYPY_COLOR} ./lib/sqlalchemy
     # pyright changes too often with not-exactly-correct errors
@@ -167,7 +167,7 @@ deps=
      pytest-xdist
      greenlet != 0.4.17
      importlib_metadata; python_version < '3.8'
-     mypy >= 0.981
+     mypy >= 1.1.1
      patch==1.*
 
 commands =