From 068c671660ea3b64d26aa05bac182b74a175c0e5 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 27 Sep 2022 09:15:21 +0100 Subject: [PATCH] fix: avoid using type variables in typevar bounds It is not allowed by the specs. Mypy tolerates it, replacing the argument with Any, according to @erictraut. Pyright reports it as an error instead. See #365, microsoft/pyright#3984 --- psycopg/psycopg/connection.py | 2 +- psycopg/psycopg/connection_async.py | 2 +- psycopg/psycopg/copy.py | 2 +- psycopg/psycopg/cursor.py | 2 +- psycopg/psycopg/cursor_async.py | 2 +- psycopg/psycopg/server_cursor.py | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index 222cd1688..bc15717cd 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -655,7 +655,7 @@ class Connection(BaseConnection[Row]): server_cursor_factory: Type[ServerCursor[Row]] row_factory: RowFactory[Row] _pipeline: Optional[Pipeline] - _Self = TypeVar("_Self", bound="Connection[Row]") + _Self = TypeVar("_Self", bound="Connection[Any]") def __init__( self, diff --git a/psycopg/psycopg/connection_async.py b/psycopg/psycopg/connection_async.py index 89f3b5802..aa02dc0d3 100644 --- a/psycopg/psycopg/connection_async.py +++ b/psycopg/psycopg/connection_async.py @@ -52,7 +52,7 @@ class AsyncConnection(BaseConnection[Row]): server_cursor_factory: Type[AsyncServerCursor[Row]] row_factory: AsyncRowFactory[Row] _pipeline: Optional[AsyncPipeline] - _Self = TypeVar("_Self", bound="AsyncConnection[Row]") + _Self = TypeVar("_Self", bound="AsyncConnection[Any]") def __init__( self, diff --git a/psycopg/psycopg/copy.py b/psycopg/psycopg/copy.py index cca5e8572..8f344517c 100644 --- a/psycopg/psycopg/copy.py +++ b/psycopg/psycopg/copy.py @@ -74,7 +74,7 @@ class BaseCopy(Generic[ConnectionType]): a file for later use. """ - _Self = TypeVar("_Self", bound="BaseCopy[ConnectionType]") + _Self = TypeVar("_Self", bound="BaseCopy[Any]") formatter: "Formatter" diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index 83b4536e7..70eebfbba 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -650,7 +650,7 @@ class BaseCursor(Generic[ConnectionType, Row]): class Cursor(BaseCursor["Connection[Any]", Row]): __module__ = "psycopg" __slots__ = () - _Self = TypeVar("_Self", bound="Cursor[Row]") + _Self = TypeVar("_Self", bound="Cursor[Any]") @overload def __init__(self: "Cursor[Row]", connection: "Connection[Row]"): diff --git a/psycopg/psycopg/cursor_async.py b/psycopg/psycopg/cursor_async.py index 0632940d6..8aa7f71d2 100644 --- a/psycopg/psycopg/cursor_async.py +++ b/psycopg/psycopg/cursor_async.py @@ -24,7 +24,7 @@ if TYPE_CHECKING: class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]): __module__ = "psycopg" __slots__ = () - _Self = TypeVar("_Self", bound="AsyncCursor[Row]") + _Self = TypeVar("_Self", bound="AsyncCursor[Any]") @overload def __init__(self: "AsyncCursor[Row]", connection: "AsyncConnection[Row]"): diff --git a/psycopg/psycopg/server_cursor.py b/psycopg/psycopg/server_cursor.py index 16f115551..3a12b5e47 100644 --- a/psycopg/psycopg/server_cursor.py +++ b/psycopg/psycopg/server_cursor.py @@ -198,7 +198,7 @@ class ServerCursorMixin(BaseCursor[ConnectionType, Row]): class ServerCursor(ServerCursorMixin["Connection[Any]", Row], Cursor[Row]): __module__ = "psycopg" __slots__ = () - _Self = TypeVar("_Self", bound="ServerCursor[Row]") + _Self = TypeVar("_Self", bound="ServerCursor[Any]") @overload def __init__( @@ -340,7 +340,7 @@ class AsyncServerCursor( ): __module__ = "psycopg" __slots__ = () - _Self = TypeVar("_Self", bound="AsyncServerCursor[Row]") + _Self = TypeVar("_Self", bound="AsyncServerCursor[Any]") @overload def __init__( -- 2.47.2