Already supported in current Mypy: https://github.com/python/mypy/issues/731.
The definition of DumperKey was wrong anyway, in a way causing mypy to
crash: see https://github.com/python/mypy/issues/14000.
Params: TypeAlias = Union[Sequence[Any], Mapping[str, Any]]
ConnectionType = TypeVar("ConnectionType", bound="BaseConnection[Any]")
PipelineCommand: TypeAlias = Callable[[], None]
-
-# TODO: make it recursive when mypy will support it
-# DumperKey: TypeAlias = Union[type, Tuple[Union[type, "DumperKey"]]]
-DumperKey: TypeAlias = Union[type, Tuple[type, ...]]
+DumperKey: TypeAlias = Union[type, Tuple["DumperKey", ...]]
# Waiting protocol types
# Copyright (C) 2020 The Psycopg Team
from abc import ABC, abstractmethod
-from typing import Any, Optional, Type, Tuple, Union, TYPE_CHECKING
+from typing import Any, Optional, Type, TYPE_CHECKING
from . import pq, abc
from . import _adapters_map
rv = rv.replace(b"\\", b"\\\\")
return rv
- def get_key(self, obj: Any, format: PyFormat) -> Union[type, Tuple[type, ...]]:
+ def get_key(self, obj: Any, format: PyFormat) -> abc.DumperKey:
"""
Implementation of the `~psycopg.abc.Dumper.get_key()` member of the
`~psycopg.abc.Dumper` protocol. Look at its definition for details.
return self.cls
sd = self._tx.get_dumper(item, format)
- return (self.cls, sd.get_key(item, format)) # type: ignore
+ return (self.cls, sd.get_key(item, format))
def upgrade(self, obj: List[Any], format: PyFormat) -> "BaseListDumper":
# If we have an oid we don't need to upgrade
return (self.cls,)
sd = self._tx.get_dumper(item, format)
- return (self.cls, sd.get_key(item, format)) # type: ignore
+ return (self.cls, sd.get_key(item, format))
def upgrade(self, obj: List[Any], format: PyFormat) -> "BaseListDumper":
# If we have an oid we don't need to upgrade
item = self._get_item(obj)
if item is not None:
sd = self._tx.get_dumper(item, self._adapt_format)
- return (self.cls, sd.get_key(item, format)) # type: ignore
+ return (self.cls, sd.get_key(item, format))
else:
return (self.cls,)
item = self._get_item(obj)
if item is not None:
sd = self._tx.get_dumper(item, self._adapt_format)
- return (self.cls, sd.get_key(item, format)) # type: ignore
+ return (self.cls, sd.get_key(item, format))
else:
return (self.cls,)
warn_unused_ignores = true
show_error_codes = true
strict = true
+enable_recursive_aliases = true
[[tool.mypy.overrides]]
module = [
-from typing import Optional, Tuple, Union
+from typing import Optional
from psycopg import pq
from psycopg.abc import Dumper, Loader, AdaptContext, PyFormat, Buffer
def load(self, data: Buffer) -> str:
return (bytes(data) * 2).decode()
-
-
-# This should be the definition of psycopg.adapt.DumperKey, but mypy doesn't
-# support recursive types. When it will, this statement will give an error
-# (unused type: ignore) so we can fix our definition.
-_DumperKey = Union[type, Tuple[Union[type, "_DumperKey"]]] # type: ignore