Commit Graph

50 Commits

Author SHA1 Message Date
Avasam
937270df0c Forbid extremely long line lengths in non-autogenerated stubs (#12537)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-08-18 16:03:34 -04:00
Sebastian Rittau
7d56cd9a6c Remove remaining bare Incompletes (#11768)
Enable Y065
2024-04-16 06:26:14 -07:00
Shantanu
88fa182253 Use PEP 570 syntax in third party stubs (#11554) 2024-03-10 14:11:43 +01:00
Ali Hamdan
2e85a70c4c psycopg2: make Range generic (#11435)
And some other small fixes
2024-02-17 07:42:53 -08:00
Mike Zimin
8010e9fef0 issue-11282: psycopg2 ReplicationConnection.cursor() return type (#11298)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-01-30 20:25:12 -08:00
fovc9
7129bd112b psycopg2: Add ReplicationCursor.consume_stream (#11283) 2024-01-18 01:54:36 +01:00
Sebastian Rittau
b6eaadcfe5 Update typing_extensions imports in third-party stubs (#11245) 2024-01-05 15:40:13 +01:00
Sebastian Rittau
23604858a6 Remove Python 3.7 branches (#11238) 2024-01-05 11:39:39 +01:00
Avasam
4246c54a12 psycopg2: improve cursor_factory params (#11085) 2023-12-06 14:29:23 -08:00
Mehdi GMIRA
64773f398d fix(psycopg2): fix copy_expert signature (#11099) 2023-12-06 08:11:41 +01:00
Avasam
4687faab8e Use ConvertibleToInt/ConvertibleToFloat in many third-party stubs (#11022)
Note: this may make the latest version of certain stubs packages incompatible with older versions of mypy and pyright.
2023-11-29 11:23:00 +00:00
Emanuele Giaquinta
b92221eb97 psycopg2: fix range annotations (#11071) 2023-11-27 08:41:09 +01:00
Alex Waygood
1d2fe59e88 Third-party stubs: remove unused type: ignores (#11063) 2023-11-23 13:35:45 +00:00
Anders Kaseorg
aabeacfdbd psycopg2: Accept Composable for cursor.mogrify (#11028)
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2023-11-14 06:16:03 -08:00
Ali Hamdan
306c30a0c7 psycopg2: Fix missing Protocol base class in file protocols (#10943)
This is an error I introduced in #10630 because I didn't know protocols
need to be explicitly inherited from in other protocol subclasses.

The added test shows the change. Basically these protocols were unusable.
2023-10-28 15:09:39 +01:00
Ali Hamdan
dd00f9d899 Complete psycopg2 (#10760) 2023-09-24 13:48:01 -07:00
Anders Kaseorg
0ea043253e Fix psycopg2.sql.SQL.join annotation (#10716) 2023-09-15 20:16:47 +02:00
Ali Hamdan
71a35b4343 psycopg2: Add missing modules, add annotations (#10630) 2023-09-13 12:11:54 +02:00
Sebastian Rittau
afe18e95a9 Add an upstream_repository field to METADATA.toml (#10487)
Closes: #10478
2023-07-20 16:45:41 +02:00
Avasam
db0149859c Add partial_stub metadata field (#10157) 2023-05-10 17:04:18 +02:00
Alex Waygood
6fd7e36e80 Add default values for third-party stubs beginning with 'P' (#9957) 2023-03-27 18:58:53 +01:00
Avasam
52ec44fa58 Improve many __(a)exit__ annotations (#9696) 2023-02-25 21:50:30 +00:00
Alex Waygood
6ba28ae547 Remove unused type: ignore comments (#9801) 2023-02-23 12:59:50 -08:00
Avasam
ed6748fb32 Stubtest settings: change ignore_missing_stub default to false (#9779)
If you're reading about this commit from an autogenerated changelog entry, this should have no user-visible impact on how the stubs are interpreted by a type checker; it's just an internal change to how typeshed's tests work.
2023-02-20 22:37:45 +00:00
Alex Waygood
7180d0223b Use typing_extensions.Self instead of _typeshed.Self (#9702) 2023-02-15 11:32:43 +01:00
Alex Waygood
a4e3cfefac Improve pre-commit config (#9563)
- Add a few more hooks. These are all very fast, and I've found them useful in other projects:
  - Autofixes:
    - `trailing-whitespace`: fixes trailing whitespace
    - `requirements-txt-fixer`: alphabetises items in `requirements.txt` files
    - `end-of-file-fixer`: makes sure every file ends with a single newline character
    - `mixed-line-ending`: Makes sure Windows users don't accidentally introduce CRLF line endings into a file that uses LF line endings
  - None-autofixes:
    - `check-yaml`: loads YAML files to validate syntax
    - `check-toml`: loads TOML files to validate syntax
    - `check-merge-conflict`: detects merge-conflict strings in files and blocks them from accidentally being committed
    - `check-case-conflict`: checks for files with names that would conflict on a case-insensitive filesystem like MacOS HFS+ or Windows FAT; blocks them from being committed.
  - Change the bot schedule to quarterly, to reduce noisy PRs
  - Change the `black` language target-version to Python 3.10, synching the setting here with the changes that were made to our `pyproject.toml` file in #7538
2023-01-18 06:29:18 -08:00
Alex Waygood
4fea314594 Replace Any with Incomplete in many places (#9558) 2023-01-18 08:48:16 +00:00
Nikita Sobolev
62a6c3d616 Annotate known magic-method return types (#9131) 2022-11-08 18:28:42 +00:00
Jelle Zijlstra
9733901770 psycopg2: __nonzero__ was removed (#8863)
Fixes #8862
2022-10-07 02:23:56 +01:00
Joel
8715951fca Improve return type for psycopg2 connect function (#8567)
When a `connection_factory` argument is provided to psycopg2's `connect` function, the function's return type now matches that of the factory output class. However, if `cursor_factory` is set and has a non-`None` value and/or `connection_factory` is not set or is `None`, the return type is simply `connection`, as before.
2022-08-20 16:34:13 -07:00
Joel
234ef7ed9d Additional return types for psycopg2 connections (#8528)
* Return types for psycopg2 dict connections

DB connection and cursor methods that deal with `dict`-style results now indicate the expected return types as implemented.

* Return types for psycopg2 namedtuple connections

DB connection and cursor methods that deal with `namedtuple` results now indicate the expected return types as implemented.

* Use ABC iterator

As required by flake8, the `Iterator` referenced in psycopg2's `extras` module has been switched to the `collections.abc.Iterator[T]` variant.

* Fix base psycopg2 cursor iter return type

The previous return type of `Self` is wrong; `cursor`'s `__iter__` method returns an `Iterator`.

* Correct return type for cursor iter and next methods

The previous attempt to fix the return type of `cursor`'s (and subclasses) `__iter__` method was misguided; they should indeed return `Self`. It's the `__next__` methods that had to be updated to return the correct record/row instance type.

* Comprehensive overloads for psycopg2 extra connections

Provides full method signatures for the `cursor` methods of the `DictConnection`, `RealDictConnection` and `NamedTupleConnection` types. Notably this includes a default value for `cursor_factory` in each case, while preserving the option to override the parameter manually.

* Have mypy ignore incompatible psycopg2 return types

The return types of the `fetch*` and `__next__` methods of `DictCursor`, `RealDictCursor` and `NamedTupleCursor` are incompatible with the base `cursor` class's corresponding methods' return types. However, this does accurately reflect reality, so ignore the mypy errors in those cases.

* Use ABC callable for psycopg2 extras module

As required by flake8, the `Callable` referenced in psycopg2's `extras` module has been switched to the `Callable` variant.

* Remove superfluous psycopg2 member overrides

Several members in the `DictCursorBase` type definition were entirely unnecessary, so they have been removed. In addition, adds a type to the `size` param of the `cursor`'s `fetchmany` method.
2022-08-16 21:48:05 -07:00
Tareq Al-Ahdal
4f6aa12446 Enhanced type hinting for psycopg2 stubs (#8500) 2022-08-08 23:08:17 +02:00
Alex Waygood
e3d4bdc91a Third-party stubs: enforce CamelCase for type alias names (#8256)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-07-19 08:23:24 +01:00
Sarah Hoffmann
4e0aaccdab Extend annotations for psycopg2.sql (#8263) 2022-07-11 16:31:39 +02:00
Jelle Zijlstra
cb9023988d psycopg2: stub improvements (#7964)
Fixes an entry from #7928 along with a number of other improvements.

I went off the C code:
https://github.com/psycopg/psycopg2/blob/master/psycopg/connection_type.c
2022-06-02 18:02:07 -07:00
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