Skip to content

Commit

Permalink
psycopg2: Fix missing Protocol base class in file protocols
Browse files Browse the repository at this point in the history
This is an error I introduced in python#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.
  • Loading branch information
hamdanal committed Oct 28, 2023
1 parent 5643362 commit 481c9ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions stubs/psycopg2/@tests/test_cases/check_extensions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import io
from typing_extensions import assert_type

import psycopg2.extensions
Expand Down Expand Up @@ -54,3 +55,8 @@ class MyCursor(psycopg2.extensions.cursor):
assert_type(dconn.cursor("test-dcur", None), psycopg2.extras.DictCursor)
assert_type(dconn.cursor("test-dcur", cursor_factory=None), psycopg2.extras.DictCursor)
assert_type(dconn.cursor("test-dcur", cursor_factory=MyCursor), MyCursor)

# file protocols
# --------------
cur = conn.cursor()
cur.copy_from(io.StringIO(), "table")
4 changes: 2 additions & 2 deletions stubs/psycopg2/psycopg2/_psycopg.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ threadsafety: int

__libpq_version__: int

class _SupportsReadAndReadline(SupportsRead[str], SupportsReadline[str]): ...
class _SupportsReadAndReadlineAndWrite(_SupportsReadAndReadline, SupportsWrite[str]): ...
class _SupportsReadAndReadline(SupportsRead[str], SupportsReadline[str], Protocol): ...
class _SupportsReadAndReadlineAndWrite(_SupportsReadAndReadline, SupportsWrite[str], Protocol): ...

class cursor:
arraysize: int
Expand Down

0 comments on commit 481c9ed

Please sign in to comment.