Skip to content

Commit c951dbb

Browse files
authored
[psycopg2] Fix file argument types (#13418)
1 parent c01e731 commit c951dbb

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

stubs/psycopg2/psycopg2/_psycopg.pyi

+15-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import datetime as dt
22
from _typeshed import ConvertibleToInt, Incomplete, SupportsRead, SupportsReadline, SupportsWrite, Unused
33
from collections.abc import Callable, Iterable, Mapping, Sequence
44
from types import TracebackType
5-
from typing import Any, Literal, NoReturn, Protocol, TypeVar, overload, type_check_only
5+
from typing import Any, Literal, NoReturn, Protocol, TextIO, TypeVar, overload, type_check_only
66
from typing_extensions import Self, TypeAlias
77

88
from psycopg2.extras import ReplicationCursor as extras_ReplicationCursor
@@ -83,7 +83,9 @@ threadsafety: int
8383

8484
__libpq_version__: int
8585

86-
class _SupportsReadAndReadline(SupportsRead[str], SupportsReadline[str], Protocol): ...
86+
_T_co = TypeVar("_T_co", covariant=True)
87+
88+
class _SupportsReadAndReadline(SupportsRead[_T_co], SupportsReadline[_T_co], Protocol[_T_co]): ...
8789

8890
class cursor:
8991
arraysize: int
@@ -120,19 +122,27 @@ class cursor:
120122
def cast(self, oid: int, s: str | bytes, /) -> Any: ...
121123
def close(self) -> None: ...
122124
def copy_expert(
123-
self, sql: str | bytes | Composable, file: _SupportsReadAndReadline | SupportsWrite[str], size: int = 8192
125+
self,
126+
sql: str | bytes | Composable,
127+
file: _SupportsReadAndReadline[bytes] | SupportsWrite[bytes] | TextIO,
128+
size: int = 8192,
124129
) -> None: ...
125130
def copy_from(
126131
self,
127-
file: _SupportsReadAndReadline,
132+
file: _SupportsReadAndReadline[bytes] | _SupportsReadAndReadline[str],
128133
table: str,
129134
sep: str = "\t",
130135
null: str = "\\N",
131136
size: int = 8192,
132137
columns: Iterable[str] | None = None,
133138
) -> None: ...
134139
def copy_to(
135-
self, file: SupportsWrite[str], table: str, sep: str = "\t", null: str = "\\N", columns: Iterable[str] | None = None
140+
self,
141+
file: SupportsWrite[bytes] | TextIO,
142+
table: str,
143+
sep: str = "\t",
144+
null: str = "\\N",
145+
columns: Iterable[str] | None = None,
136146
) -> None: ...
137147
def execute(self, query: str | bytes | Composable, vars: _Vars = None) -> None: ...
138148
def executemany(self, query: str | bytes | Composable, vars_list: Iterable[_Vars]) -> None: ...

0 commit comments

Comments
 (0)