diff --git a/stdlib/2and3/_csv.pyi b/stdlib/2and3/_csv.pyi index 1c4c26ef2073..5278f69a515f 100644 --- a/stdlib/2and3/_csv.pyi +++ b/stdlib/2and3/_csv.pyi @@ -1,6 +1,6 @@ import sys -from typing import Any, Iterable, Iterator, List, Optional, Sequence, Text +from typing import Any, Iterable, Iterator, List, Optional, Protocol, Sequence, Text, Union QUOTE_ALL: int QUOTE_MINIMAL: int @@ -39,9 +39,10 @@ class _writer: def writerows(self, rows: Iterable[Sequence[Any]]) -> None: ... -# TODO: precise type -def writer(csvfile: Any, dialect: Any = ..., **fmtparams: Any) -> _writer: ... -def reader(csvfile: Iterable[Text], dialect: Any = ..., **fmtparams: Any) -> _reader: ... +class _Writer(Protocol): + def write(self, s: str) -> Any: ... +def writer(csvfile: _Writer, dialect: Union[Dialect, str] = ..., **fmtparams: Any) -> _writer: ... +def reader(csvfile: Iterable[Text], dialect: Union[Dialect, str] = ..., **fmtparams: Any) -> _reader: ... def register_dialect(name: str, dialect: Any = ..., **fmtparams: Any) -> None: ... def unregister_dialect(name: str) -> None: ... def get_dialect(name: str) -> Dialect: ...