From 3ed7e3ba507c4a7a9aa8809df583af2c3a38ffe7 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 8 May 2022 05:01:20 +0100 Subject: [PATCH] csv: annotate keyword arguments in various functions and methods (#7788) --- stdlib/_csv.pyi | 42 ++++++++++++++++++++++-- stdlib/csv.pyi | 33 +++++++++++++++---- tests/stubtest_allowlists/py3_common.txt | 2 ++ 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/stdlib/_csv.pyi b/stdlib/_csv.pyi index 6107df8fb..7d15365d3 100644 --- a/stdlib/_csv.pyi +++ b/stdlib/_csv.pyi @@ -41,9 +41,45 @@ class _writer: def writerow(self, row: Iterable[Any]) -> Any: ... def writerows(self, rows: Iterable[Iterable[Any]]) -> None: ... -def writer(csvfile: SupportsWrite[str], dialect: _DialectLike = ..., **fmtparams: Any) -> _writer: ... -def reader(csvfile: Iterable[str], dialect: _DialectLike = ..., **fmtparams: Any) -> _reader: ... -def register_dialect(name: str, dialect: Any = ..., **fmtparams: Any) -> None: ... +def writer( + csvfile: SupportsWrite[str], + dialect: _DialectLike = ..., + *, + delimiter: str = ..., + quotechar: str | None = ..., + escapechar: str | None = ..., + doublequote: bool = ..., + skipinitialspace: bool = ..., + lineterminator: str = ..., + quoting: _QuotingType = ..., + strict: bool = ..., +) -> _writer: ... +def reader( + csvfile: Iterable[str], + dialect: _DialectLike = ..., + *, + delimiter: str = ..., + quotechar: str | None = ..., + escapechar: str | None = ..., + doublequote: bool = ..., + skipinitialspace: bool = ..., + lineterminator: str = ..., + quoting: _QuotingType = ..., + strict: bool = ..., +) -> _reader: ... +def register_dialect( + name: str, + dialect: Any = ..., + *, + delimiter: str = ..., + quotechar: str | None = ..., + escapechar: str | None = ..., + doublequote: bool = ..., + skipinitialspace: bool = ..., + lineterminator: str = ..., + quoting: _QuotingType = ..., + strict: bool = ..., +) -> None: ... def unregister_dialect(name: str) -> None: ... def get_dialect(name: str) -> Dialect: ... def list_dialects() -> list[str]: ... diff --git a/stdlib/csv.pyi b/stdlib/csv.pyi index 3f2198ff8..de69c71ad 100644 --- a/stdlib/csv.pyi +++ b/stdlib/csv.pyi @@ -91,8 +91,15 @@ class DictReader(Generic[_T], Iterator[_DictReadMapping[_T, str]]): restkey: str | None = ..., restval: str | None = ..., dialect: _DialectLike = ..., - *args: Any, - **kwds: Any, + *, + delimiter: str = ..., + quotechar: str | None = ..., + escapechar: str | None = ..., + doublequote: bool = ..., + skipinitialspace: bool = ..., + lineterminator: str = ..., + quoting: _QuotingType = ..., + strict: bool = ..., ) -> None: ... @overload def __init__( @@ -102,8 +109,15 @@ class DictReader(Generic[_T], Iterator[_DictReadMapping[_T, str]]): restkey: str | None = ..., restval: str | None = ..., dialect: _DialectLike = ..., - *args: Any, - **kwds: Any, + *, + delimiter: str = ..., + quotechar: str | None = ..., + escapechar: str | None = ..., + doublequote: bool = ..., + skipinitialspace: bool = ..., + lineterminator: str = ..., + quoting: _QuotingType = ..., + strict: bool = ..., ) -> None: ... def __iter__(self: Self) -> Self: ... def __next__(self) -> _DictReadMapping[_T, str]: ... @@ -120,8 +134,15 @@ class DictWriter(Generic[_T]): restval: Any | None = ..., extrasaction: Literal["raise", "ignore"] = ..., dialect: _DialectLike = ..., - *args: Any, - **kwds: Any, + *, + delimiter: str = ..., + quotechar: str | None = ..., + escapechar: str | None = ..., + doublequote: bool = ..., + skipinitialspace: bool = ..., + lineterminator: str = ..., + quoting: _QuotingType = ..., + strict: bool = ..., ) -> None: ... if sys.version_info >= (3, 8): def writeheader(self) -> Any: ... diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 687aa32b5..89f804075 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -78,6 +78,8 @@ csv.Dialect.doublequote csv.Dialect.lineterminator csv.Dialect.quoting csv.Dialect.skipinitialspace +csv.DictReader.__init__ # runtime sig has *args but will error if more than 5 positional args are supplied +csv.DictWriter.__init__ # runtime sig has *args but will error if more than 5 positional args are supplied ctypes.Array.__iter__ # mypy doesn't support using __getitem__ instead of __iter__ so this is here https://github.com/python/mypy/issues/2220 ctypes.Array._type_ # _type_ and _length_ are abstract, https://github.com/python/typeshed/pull/6361 ctypes.Array._length_