From b7a611e21164b04450ec811af03c9c0dfb821c6d Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 6 Jan 2020 20:59:07 -0800 Subject: [PATCH] csv: more precise types, remove TODO (#3581) --- stdlib/2and3/_csv.pyi | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stdlib/2and3/_csv.pyi b/stdlib/2and3/_csv.pyi index 1c4c26ef2..5278f69a5 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: ...