Skip to content

Commit 119e390

Browse files
committed
Annotations for psycopg2.ConnectionInfo
These annotations come from the documentation here: https://www.psycopg.org/docs/extensions.html#psycopg2.extensions.ConnectionInfo If there was doubt, I referred to the libpq documentation cited by psycopg2's docs. I wasn't completely sure about `dsn_parameters`. Psycopg2's docs list it as an `dict`, and the example suggests it's a `dict[str, str]` at that. From psycopg2's source I found https://github.com/psycopg/psycopg2/blob/1d3a89a0bba621dc1cc9b32db6d241bd2da85ad1/psycopg/conninfo_type.c#L183-L206 which is implemented here: https://github.com/psycopg/psycopg2/blob/1d3a89a0bba621dc1cc9b32db6d241bd2da85ad1/psycopg/utils.c#L251-L279 I'm no expert in CPython's API, but this looks to me like it's building a `dict[str, str]`. Additionally, the libpq docs https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PQCONNINFO https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PQCONNDEFAULTS show that the underlying data just consists of strings. Additionally, I'm pretty sure from this chunk of source https://github.com/psycopg/psycopg2/blob/1d3a89a0bba621dc1cc9b32db6d241bd2da85ad1/psycopg/conninfo_type.c#L581-L598 That `ConnectionInfo.__init__` takes one positional-only argument, which must be a `psycopg2.connection`. But I don't think users are intended to be constructing this type, so I've not added that annotation.
1 parent 40d6592 commit 119e390

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

stubs/psycopg2/psycopg2/_psycopg.pyi

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -157,27 +157,27 @@ class Column:
157157
def __setstate__(self, state): ...
158158

159159
class ConnectionInfo:
160-
backend_pid: Any
161-
dbname: Any
162-
dsn_parameters: Any
163-
error_message: Any
164-
host: Any
165-
needs_password: Any
166-
options: Any
167-
password: Any
168-
port: Any
169-
protocol_version: Any
170-
server_version: Any
171-
socket: Any
172-
ssl_attribute_names: Any
173-
ssl_in_use: Any
174-
status: Any
175-
transaction_status: Any
176-
used_password: Any
177-
user: Any
160+
backend_pid: int
161+
dbname: str
162+
dsn_parameters: dict
163+
error_message: str | None
164+
host: str
165+
needs_password: bool
166+
options: str
167+
password: str
168+
port: int
169+
protocol_version: int
170+
server_version: int
171+
socket: int
172+
ssl_attribute_names: list[str]
173+
ssl_in_use: bool
174+
status: int
175+
transaction_status: int
176+
used_password: bool
177+
user: str
178178
def __init__(self, *args, **kwargs) -> None: ...
179-
def parameter_status(self, *args, **kwargs): ...
180-
def ssl_attribute(self, *args, **kwargs): ...
179+
def parameter_status(self, name: str) -> str | None: ...
180+
def ssl_attribute(self, name: str) -> str | None: ...
181181

182182
class DataError(psycopg2.DatabaseError): ...
183183
class DatabaseError(psycopg2.Error): ...

0 commit comments

Comments
 (0)