From 002ab1703fc52af9d2f8825ccad1420c47f2862b Mon Sep 17 00:00:00 2001 From: Peter Law Date: Wed, 1 Sep 2021 22:49:46 +0100 Subject: [PATCH 1/2] Relax DictWriter.fieldnames closer to implementation I think this might actually work if you pass just an Iterable, however since that would allow passing a generator (which would definitely not work correctly) I've kept this as Collection. Fix https://github.com/python/typeshed/issues/5993 --- stdlib/csv.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/csv.pyi b/stdlib/csv.pyi index 6e242f495948..3775284f95b1 100644 --- a/stdlib/csv.pyi +++ b/stdlib/csv.pyi @@ -17,7 +17,7 @@ from _csv import ( unregister_dialect as unregister_dialect, writer as writer, ) -from typing import Any, Generic, Iterable, Iterator, Mapping, Sequence, Type, TypeVar, overload +from typing import Any, Collection, Generic, Iterable, Iterator, Mapping, Sequence, Type, TypeVar, overload if sys.version_info >= (3, 8): from typing import Dict as _DictReadMapping @@ -78,14 +78,14 @@ class DictReader(Generic[_T], Iterator[_DictReadMapping[_T, str]]): def __next__(self) -> _DictReadMapping[_T, str]: ... class DictWriter(Generic[_T]): - fieldnames: Sequence[_T] + fieldnames: Collection[_T] restval: Any | None extrasaction: str writer: _writer def __init__( self, f: Any, - fieldnames: Sequence[_T], + fieldnames: Collection[_T], restval: Any | None = ..., extrasaction: str = ..., dialect: _DialectLike = ..., From f8af7bcf90b8eae2d26c2b2f39c0e297f8f20d9b Mon Sep 17 00:00:00 2001 From: Peter Law Date: Thu, 2 Sep 2021 18:48:41 +0100 Subject: [PATCH 2/2] Prefer to import collections types from collections.abc --- stdlib/csv.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/csv.pyi b/stdlib/csv.pyi index 3775284f95b1..0b69cb2272d3 100644 --- a/stdlib/csv.pyi +++ b/stdlib/csv.pyi @@ -17,7 +17,8 @@ from _csv import ( unregister_dialect as unregister_dialect, writer as writer, ) -from typing import Any, Collection, Generic, Iterable, Iterator, Mapping, Sequence, Type, TypeVar, overload +from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence +from typing import Any, Generic, Type, TypeVar, overload if sys.version_info >= (3, 8): from typing import Dict as _DictReadMapping