]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Other classes have their __module__ specified
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 24 Nov 2020 02:07:00 +0000 (02:07 +0000)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 24 Nov 2020 02:07:00 +0000 (02:07 +0000)
These required jumping through hoop to have mypy and documentation
agreeing, now it's more natural.

docs/lib/pg3_docs.py
psycopg3/psycopg3/_transform.py
psycopg3/psycopg3/connection.py
psycopg3/psycopg3/copy.py
psycopg3/psycopg3/cursor.py
psycopg3/psycopg3/pq/pq_ctypes.py
psycopg3/psycopg3/transaction.py

index ae73dbe6057ef39d6590a0429d51f0e7c295d6cb..cdb219ff0d3579de45a15da7242349a69d5192a6 100644 (file)
@@ -15,8 +15,6 @@ def before_process_signature(app, obj, bound_method):
         # Drop "return: None" from the function signatures
         if ann["return"] is None:
             del ann["return"]
-        elif ann["return"] == "PGcancel":
-            ann["return"] = "psycopg3.pq.PGcancel"
 
 
 def process_signature(
index 360a945a420dd8c54412d02f1af40540a053f279..4fb23043d06afccedd7fa78a93d57070dc4a3333 100644 (file)
@@ -31,6 +31,8 @@ class Transformer:
     state so adapting several values of the same type can be optimised.
     """
 
+    __module__ = "psycopg3.adapt"
+
     def __init__(self, context: AdaptContext = None):
         self._dumpers: DumpersMap
         self._loaders: LoadersMap
index 48097661f2596c4419aab6c80055d1ee09c070d8..8813dcb3404dcb0bbf0bacad64e61539f040a5b5 100644 (file)
@@ -39,7 +39,7 @@ connect: Callable[[str], PQGen["PGconn"]]
 execute: Callable[["PGconn"], PQGen[List["PGresult"]]]
 
 if TYPE_CHECKING:
-    import psycopg3
+    from .cursor import AsyncCursor, Cursor
     from .pq.proto import PGconn, PGresult
 
 if pq.__impl__ == "c":
@@ -68,8 +68,10 @@ class Notify(NamedTuple):
     """The PID of the backend process which sent the notification."""
 
 
+Notify.__module__ = "psycopg3"
+
 NoticeHandler = Callable[[e.Diagnostic], None]
-NotifyHandler = Callable[["psycopg3.Notify"], None]
+NotifyHandler = Callable[[Notify], None]
 
 
 class BaseConnection:
@@ -96,9 +98,7 @@ class BaseConnection:
     ConnStatus = pq.ConnStatus
     TransactionStatus = pq.TransactionStatus
 
-    cursor_factory: Union[
-        Type["psycopg3.Cursor"], Type["psycopg3.AsyncCursor"]
-    ]
+    cursor_factory: Union[Type["Cursor"], Type["AsyncCursor"]]
 
     def __init__(self, pgconn: "PGconn"):
         self.pgconn = pgconn  # TODO: document this
@@ -229,7 +229,9 @@ class Connection(BaseConnection):
     Wrapper for a connection to the database.
     """
 
-    cursor_factory: Type["psycopg3.Cursor"]
+    __module__ = "psycopg3"
+
+    cursor_factory: Type["Cursor"]
 
     def __init__(self, pgconn: "PGconn"):
         super().__init__(pgconn)
@@ -273,9 +275,7 @@ class Connection(BaseConnection):
         """Close the database connection."""
         self.pgconn.finish()
 
-    def cursor(
-        self, name: str = "", format: Format = Format.TEXT
-    ) -> "psycopg3.Cursor":
+    def cursor(self, name: str = "", format: Format = Format.TEXT) -> "Cursor":
         """
         Return a new `Cursor` to send commands and queries to the connection.
         """
@@ -370,7 +370,7 @@ class Connection(BaseConnection):
                     result, encoding=self.client_encoding
                 )
 
-    def notifies(self) -> Iterator["psycopg3.Notify"]:
+    def notifies(self) -> Iterator[Notify]:
         """
         Yield `Notify` objects as soon as they are received from the database.
         """
@@ -394,7 +394,9 @@ class AsyncConnection(BaseConnection):
     Asynchronous wrapper for a connection to the database.
     """
 
-    cursor_factory: Type["psycopg3.AsyncCursor"]
+    __module__ = "psycopg3"
+
+    cursor_factory: Type["AsyncCursor"]
 
     def __init__(self, pgconn: "PGconn"):
         super().__init__(pgconn)
@@ -433,7 +435,7 @@ class AsyncConnection(BaseConnection):
 
     async def cursor(
         self, name: str = "", format: Format = Format.TEXT
-    ) -> "psycopg3.AsyncCursor":
+    ) -> "AsyncCursor":
         """
         Return a new `AsyncCursor` to send commands and queries to the connection.
         """
@@ -529,7 +531,7 @@ class AsyncConnection(BaseConnection):
                     result, encoding=self.client_encoding
                 )
 
-    async def notifies(self) -> AsyncIterator["psycopg3.Notify"]:
+    async def notifies(self) -> AsyncIterator[Notify]:
         while 1:
             async with self.lock:
                 ns = await self.wait(notifies(self.pgconn))
index 7165120fc55c153878ae00d37444a46b199b6140..931bddb0a5f49de15660b8aa53bf024c216668bb 100644 (file)
@@ -127,6 +127,8 @@ _bsrepl_re = re.compile(b"[\b\t\n\v\f\r\\\\]")
 class Copy(BaseCopy["Connection"]):
     """Manage a :sql:`COPY` operation."""
 
+    __module__ = "psycopg3"
+
     def read(self) -> bytes:
         """Read a row of data after a :sql:`COPY TO` operation.
 
@@ -204,6 +206,8 @@ class Copy(BaseCopy["Connection"]):
 class AsyncCopy(BaseCopy["AsyncConnection"]):
     """Manage an asynchronous :sql:`COPY` operation."""
 
+    __module__ = "psycopg3"
+
     async def read(self) -> bytes:
         if self._finished:
             return b""
index 7bd54d20d36cd8cbd86e74429942cad983e26e44..7c424d5c8f8c4ec7e6da5796670ab83e2081d9d5 100644 (file)
@@ -43,6 +43,9 @@ else:
 
 
 class Column(Sequence[Any]):
+
+    __module__ = "psycopg3"
+
     def __init__(self, pgresult: "PGresult", index: int, encoding: str):
         self._pgresult = pgresult
         self._index = index
@@ -413,6 +416,8 @@ class BaseCursor(Generic[ConnectionType]):
 
 
 class Cursor(BaseCursor["Connection"]):
+    __module__ = "psycopg3"
+
     def __enter__(self) -> "Cursor":
         return self
 
@@ -549,6 +554,8 @@ class Cursor(BaseCursor["Connection"]):
 
 
 class AsyncCursor(BaseCursor["AsyncConnection"]):
+    __module__ = "psycopg3"
+
     async def __aenter__(self) -> "AsyncCursor":
         return self
 
index 7d27dc633ab341ff1b0ce6333481f2d15b496178..9cb8bcad7bdd9144f4c7cb77f8bdbb01ff32e2a0 100644 (file)
@@ -58,6 +58,7 @@ class PGconn:
     Python representation of a libpq connection.
     """
 
+    __module__ = "psycopg3.pq"
     __slots__ = (
         "pgconn_ptr",
         "notice_handler",
@@ -578,6 +579,7 @@ class PGresult:
     Python representation of a libpq result.
     """
 
+    __module__ = "psycopg3.pq"
     __slots__ = ("pgresult_ptr",)
 
     def __init__(self, pgresult_ptr: impl.PGresult_struct):
@@ -689,6 +691,7 @@ class PGcancel:
     Created by `PGconn.get_cancel()`.
     """
 
+    __module__ = "psycopg3.pq"
     __slots__ = ("pgcancel_ptr",)
 
     def __init__(self, pgcancel_ptr: impl.PGcancel_struct):
@@ -729,6 +732,8 @@ class Conninfo:
     Utility object to manipulate connection strings.
     """
 
+    __module__ = "psycopg3.pq"
+
     @classmethod
     def get_defaults(cls) -> List[ConninfoOption]:
         opts = impl.PQconndefaults()
@@ -780,6 +785,8 @@ class Escaping:
     Utility object to escape strings for SQL interpolation.
     """
 
+    __module__ = "psycopg3.pq"
+
     def __init__(self, conn: Optional[PGconn] = None):
         self.conn = conn
 
index b42ed81ea6f9fc7e9bfece030712faf3eadff458..8130e44acd01c1c3d4c6a21478864c0616d0f4b3 100644 (file)
@@ -28,6 +28,8 @@ class Rollback(Exception):
     enclosing transactions contexts up to and including the one specified.
     """
 
+    __module__ = "psycopg3"
+
     def __init__(
         self,
         transaction: Union["Transaction", "AsyncTransaction", None] = None,
@@ -147,6 +149,8 @@ class Transaction(BaseTransaction["Connection"]):
     Returned by `Connection.transaction()` to handle a transaction block.
     """
 
+    __module__ = "psycopg3"
+
     def __enter__(self) -> "Transaction":
         with self._conn.lock:
             self._execute(self._enter_commands())
@@ -193,6 +197,8 @@ class AsyncTransaction(BaseTransaction["AsyncConnection"]):
     Returned by `AsyncConnection.transaction()` to handle a transaction block.
     """
 
+    __module__ = "psycopg3"
+
     async def __aenter__(self) -> "AsyncTransaction":
         async with self._conn.lock:
             await self._execute(self._enter_commands())