Commit Graph

15 Commits

Author SHA1 Message Date
PIG208
5be7976fe3 psycopg2: Fix the return type of Composable.as_string (#7984)
Signed-off-by: Zixuan James Li <359101898@qq.com>
2022-05-29 15:15:56 -07:00
David Robertson
e5594aac60 Annotations for psycopg2.ConnectionInfo (#7834)
* 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

    1d3a89a0bb/psycopg/conninfo_type.c (L183-L206)

which is implemented here:

    1d3a89a0bb/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

    1d3a89a0bb/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.

* Annotate `connection.info` and related attributes

* Make ConnectionInfo attributes properties

According to 1d3a89a0bb/psycopg/conninfo_type.c (L534-L563)

* Mark connection attributes as readonly

according to 8ef195f2ff/psycopg/connection_type.c (L1244)

* Explain why some properties aren't `T | None`
2022-05-21 07:38:52 -07:00
Sebastian Rittau
2a0fc1b582 Annotate Error and Diagnostics (#7671)
Move cursor class to top of file so it can be used as base class
2022-04-21 21:19:34 -07:00
Alex Waygood
b093c90a94 Use TypeAlias for type aliases where possible, part II (#7667) 2022-04-20 20:02:47 +01:00
Alex Waygood
740193a8fc Use TypeAlias where possible for type aliases (#7630) 2022-04-15 18:01:00 -07:00
Bao
79c654ef43 psycopg2: correct return type (#7607)
Fixes the return type of `psycopg2.cursor.fetchone()` to match the psycopg2 code:

1d3a89a0bb/psycopg/cursor_type.c (L647-L651)
1d3a89a0bb/psycopg/cursor_type.c (L748-L786)

It also matches the [psycopg2 documentation](https://www.psycopg.org/docs/cursor.html?highlight=copy_from#cursor.fetchone) as well as the [DB-API](https://peps.python.org/pep-0249/#fetchone)
2022-04-07 15:36:26 -07:00
Anders Kaseorg
b78f0c21ba psycopg2: Accept Composable in place of query string (#7494)
https://www.psycopg.org/docs/sql.html#psycopg2.sql.Composable
“Composable objects can be passed directly to execute(),
executemany(), copy_expert() in place of the query string.”

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-03-15 20:47:30 -07:00
Sebastian Rittau
889164cb0c psycopg2: Annotate cursor execute* and dunder methods (#7460) 2022-03-08 08:13:19 -08:00
Alex Waygood
64af11c78f Correct several positional-only differences in third-party stubs (#7352) 2022-02-22 06:49:51 -08:00
Alex Waygood
8d5d2520ac Use PEP 585 syntax wherever possible (#6717) 2021-12-28 11:31:43 +01:00
Daniel Foerster
506be4fb0a Fix psycopg2 connection.cursor() stub (#6470)
Adds `scrollable=` argument missing since psycopg2 2.5 and prevents `Any` from being hinted when `cursor_factory=` is passed.
2021-12-02 17:50:25 +01:00
Joachim Jablon
e96dde7618 psycopg2: use Error and Warning from _psycopg.pyi in errors.pyi (#6454) 2021-11-30 15:26:50 +02:00
Joachim Jablon
7e836db2f3 Move abstract methods to AbstractConnectionPool (#6340) 2021-11-23 09:40:45 +01:00
Sebastian Rittau
9f86972350 Add star to all non-0.1 versions (#6146) 2021-10-11 13:41:19 -07:00
Jukka Lehtosalo
a0f199727b Stubs for psycopg2 (#5783) 2021-07-15 17:29:56 +02:00