Skip to content

Commit 3ed7e3b

Browse files
authored
csv: annotate keyword arguments in various functions and methods (#7788)
1 parent 4e946b7 commit 3ed7e3b

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

stdlib/_csv.pyi

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,45 @@ class _writer:
4141
def writerow(self, row: Iterable[Any]) -> Any: ...
4242
def writerows(self, rows: Iterable[Iterable[Any]]) -> None: ...
4343

44-
def writer(csvfile: SupportsWrite[str], dialect: _DialectLike = ..., **fmtparams: Any) -> _writer: ...
45-
def reader(csvfile: Iterable[str], dialect: _DialectLike = ..., **fmtparams: Any) -> _reader: ...
46-
def register_dialect(name: str, dialect: Any = ..., **fmtparams: Any) -> None: ...
44+
def writer(
45+
csvfile: SupportsWrite[str],
46+
dialect: _DialectLike = ...,
47+
*,
48+
delimiter: str = ...,
49+
quotechar: str | None = ...,
50+
escapechar: str | None = ...,
51+
doublequote: bool = ...,
52+
skipinitialspace: bool = ...,
53+
lineterminator: str = ...,
54+
quoting: _QuotingType = ...,
55+
strict: bool = ...,
56+
) -> _writer: ...
57+
def reader(
58+
csvfile: Iterable[str],
59+
dialect: _DialectLike = ...,
60+
*,
61+
delimiter: str = ...,
62+
quotechar: str | None = ...,
63+
escapechar: str | None = ...,
64+
doublequote: bool = ...,
65+
skipinitialspace: bool = ...,
66+
lineterminator: str = ...,
67+
quoting: _QuotingType = ...,
68+
strict: bool = ...,
69+
) -> _reader: ...
70+
def register_dialect(
71+
name: str,
72+
dialect: Any = ...,
73+
*,
74+
delimiter: str = ...,
75+
quotechar: str | None = ...,
76+
escapechar: str | None = ...,
77+
doublequote: bool = ...,
78+
skipinitialspace: bool = ...,
79+
lineterminator: str = ...,
80+
quoting: _QuotingType = ...,
81+
strict: bool = ...,
82+
) -> None: ...
4783
def unregister_dialect(name: str) -> None: ...
4884
def get_dialect(name: str) -> Dialect: ...
4985
def list_dialects() -> list[str]: ...

stdlib/csv.pyi

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,15 @@ class DictReader(Generic[_T], Iterator[_DictReadMapping[_T, str]]):
9191
restkey: str | None = ...,
9292
restval: str | None = ...,
9393
dialect: _DialectLike = ...,
94-
*args: Any,
95-
**kwds: Any,
94+
*,
95+
delimiter: str = ...,
96+
quotechar: str | None = ...,
97+
escapechar: str | None = ...,
98+
doublequote: bool = ...,
99+
skipinitialspace: bool = ...,
100+
lineterminator: str = ...,
101+
quoting: _QuotingType = ...,
102+
strict: bool = ...,
96103
) -> None: ...
97104
@overload
98105
def __init__(
@@ -102,8 +109,15 @@ class DictReader(Generic[_T], Iterator[_DictReadMapping[_T, str]]):
102109
restkey: str | None = ...,
103110
restval: str | None = ...,
104111
dialect: _DialectLike = ...,
105-
*args: Any,
106-
**kwds: Any,
112+
*,
113+
delimiter: str = ...,
114+
quotechar: str | None = ...,
115+
escapechar: str | None = ...,
116+
doublequote: bool = ...,
117+
skipinitialspace: bool = ...,
118+
lineterminator: str = ...,
119+
quoting: _QuotingType = ...,
120+
strict: bool = ...,
107121
) -> None: ...
108122
def __iter__(self: Self) -> Self: ...
109123
def __next__(self) -> _DictReadMapping[_T, str]: ...
@@ -120,8 +134,15 @@ class DictWriter(Generic[_T]):
120134
restval: Any | None = ...,
121135
extrasaction: Literal["raise", "ignore"] = ...,
122136
dialect: _DialectLike = ...,
123-
*args: Any,
124-
**kwds: Any,
137+
*,
138+
delimiter: str = ...,
139+
quotechar: str | None = ...,
140+
escapechar: str | None = ...,
141+
doublequote: bool = ...,
142+
skipinitialspace: bool = ...,
143+
lineterminator: str = ...,
144+
quoting: _QuotingType = ...,
145+
strict: bool = ...,
125146
) -> None: ...
126147
if sys.version_info >= (3, 8):
127148
def writeheader(self) -> Any: ...

tests/stubtest_allowlists/py3_common.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ csv.Dialect.doublequote
7878
csv.Dialect.lineterminator
7979
csv.Dialect.quoting
8080
csv.Dialect.skipinitialspace
81+
csv.DictReader.__init__ # runtime sig has *args but will error if more than 5 positional args are supplied
82+
csv.DictWriter.__init__ # runtime sig has *args but will error if more than 5 positional args are supplied
8183
ctypes.Array.__iter__ # mypy doesn't support using __getitem__ instead of __iter__ so this is here https://github.com/python/mypy/issues/2220
8284
ctypes.Array._type_ # _type_ and _length_ are abstract, https://github.com/python/typeshed/pull/6361
8385
ctypes.Array._length_

0 commit comments

Comments
 (0)