]> git.ipfire.org Git - thirdparty/psycopg.git/commit
Fix `Connection.connect()` return type
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 29 Apr 2021 16:11:14 +0000 (18:11 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 29 Apr 2021 17:13:48 +0000 (19:13 +0200)
commitd142943902a82f158969f5500e3f353adf2fd1f0
tree4a686ef08242e1cb7b694c0b5e2be2075c57af18
parent7aa7b470221a777223de3ce087a5234c4f75d697
Fix `Connection.connect()` return type

Now `connect()` returns a `Connection[Tuple]`, whereas
`connect(row_factory=something)` return the type of what row factory
produces. The implementation of this is somewhat brittle, but that's
mypy for you: @dlax (thank you!) noticed that defining `**kwargs:
Union[str, int]` helped to disambiguate the row_factory param. I guess
we will make a best-effort to maintain this "interface". Everything is
to be documented.

Strangely, mypy cannot figure out the type of

    conn = await self.connection_class.connect(
        self.conninfo, **self.kwargs
    )

in the async pool, but it can for the sync one (without the `await`).
Added explicit type to disambiguate, on both the classes, for symmetry.

Added regression tests to verify that refactoring doesn't break type
inference.
psycopg3/psycopg3/connection.py
psycopg3/psycopg3/pool/async_pool.py
psycopg3/psycopg3/pool/pool.py
tests/test_typing.py
tests/typing_example.py