Closed dependabot[bot] closed 1 year ago
synapse/storage/engines/postgres.py:35: error: Type argument "connection" of "BaseDatabaseEngine" must be a subtype of "Connection" [type-var]
synapse/storage/engines/postgres.py:35: error: Type argument "cursor" of "BaseDatabaseEngine" must be a subtype of "Cursor" [type-var]
synapse/storage/engines/postgres.py:105: error: Argument 1 to "get_db_locale" of "PostgresEngine" has incompatible type "cursor"; expected "Cursor" [arg-type]
synapse/storage/engines/postgres.py:105: note: Following member(s) of "cursor" have conflicts:
synapse/storage/engines/postgres.py:105: note: description: expected "Optional[Sequence[Tuple[str, Optional[Any], Optional[int], Optional[int], Optional[int], Optional[int], Optional[int]]]]", got "Optional[Tuple[Column, ...]]"
synapse/storage/engines/postgres.py:132: error: Argument 1 of "check_new_database" is incompatible with supertype "BaseDatabaseEngine"; supertype defines the argument type as "cursor" [override]
synapse/storage/engines/postgres.py:132: note: This violates the Liskov substitution principle
synapse/storage/engines/postgres.py:132: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
tests/server.py:1030: error: Subclass of "Connection" and "connection" cannot exist: would have incompatible method signatures [unreachable]
tests/server.py:1031: error: Statement is unreachable [unreachable]
tests/server.py:1077: error: Subclass of "Connection" and "connection" cannot exist: would have incompatible method signatures [unreachable]
tests/server.py:1078: error: Statement is unreachable [unreachable]
https://github.com/python/typeshed/commits/main/stubs/psycopg2 for recent changes
Guessing that this is https://github.com/python/typeshed/pull/10630.
I think the problem is that I wrote a protocol for Cursor.description
based on https://peps.python.org/pep-0249/#description. But psycopg2 uses a Column
type: https://github.com/python/typeshed/blame/d56b0b80d80d4736a21c0dfcc186dfd3ad152bf5/stubs/psycopg2/psycopg2/_psycopg.pyi#L179, rather than an inner tuple like sqlite3: https://github.com/python/typeshed/blob/d56b0b80d80d4736a21c0dfcc186dfd3ad152bf5/stdlib/sqlite3/dbapi2.pyi#L400. (Column defines a getitem so it presumably still looks like a tuple?)
So now mypy can see that psycopg.extensions.cursor doesn't satisfy the protocol I wrote.
I can't see a clean way to fix this, and there's only one call site: https://github.com/matrix-org/synapse/blob/2a0f86f88fdb3d450212541ba7db57df6a184ae3/synapse/storage/database.py#L1045-L1057
So I'm going to just change description to be Sequence[Any]
.
A newer version of types-psycopg2 exists, but since this PR has been edited by someone other than Dependabot I haven't updated it. You'll get a PR for the updated version as normal once this PR is merged.
@DMRobertson Is it worth recreating this to see if it works better?
@DMRobertson Is it worth recreating this to see if it works better?
I'd be surprised if it worked without the tweak I added in 3049b8e
(#16343), but I'm happy to recreate it and try. We can always resurrect or cherry-pick that change.
@dependabot recreate
Superseded by #16381.
Bumps types-psycopg2 from 2.9.21.11 to 2.9.21.13.
Commits
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show