1
+ from _typeshed import SupportsWrite
1
2
from collections .abc import Iterable , Iterator
2
- from typing import Any , Protocol , Union
3
+ from typing import Any , Union
3
4
from typing_extensions import Literal , TypeAlias
4
5
5
6
__version__ : str
@@ -9,6 +10,10 @@ QUOTE_MINIMAL: Literal[0]
9
10
QUOTE_NONE : Literal [3 ]
10
11
QUOTE_NONNUMERIC : Literal [2 ]
11
12
13
+ # Ideally this would be `QUOTE_ALL | QUOTE_MINIMAL | QUOTE_NONE | QUOTE_NONNUMERIC`
14
+ # However, using literals in situations like these can cause false-positives (see #7258)
15
+ _QuotingType : TypeAlias = int
16
+
12
17
class Error (Exception ): ...
13
18
14
19
class Dialect :
@@ -18,26 +23,25 @@ class Dialect:
18
23
doublequote : bool
19
24
skipinitialspace : bool
20
25
lineterminator : str
21
- quoting : int
22
- strict : int
26
+ quoting : _QuotingType
27
+ strict : bool
23
28
def __init__ (self ) -> None : ...
24
29
25
30
_DialectLike : TypeAlias = Union [str , Dialect , type [Dialect ]]
26
31
27
32
class _reader (Iterator [list [str ]]):
28
- dialect : Dialect
33
+ @property
34
+ def dialect (self ) -> Dialect : ...
29
35
line_num : int
30
36
def __next__ (self ) -> list [str ]: ...
31
37
32
38
class _writer :
33
- dialect : Dialect
39
+ @property
40
+ def dialect (self ) -> Dialect : ...
34
41
def writerow (self , row : Iterable [Any ]) -> Any : ...
35
42
def writerows (self , rows : Iterable [Iterable [Any ]]) -> None : ...
36
43
37
- class _Writer (Protocol ):
38
- def write (self , __s : str ) -> object : ...
39
-
40
- def writer (csvfile : _Writer , dialect : _DialectLike = ..., ** fmtparams : Any ) -> _writer : ...
44
+ def writer (csvfile : SupportsWrite [str ], dialect : _DialectLike = ..., ** fmtparams : Any ) -> _writer : ...
41
45
def reader (csvfile : Iterable [str ], dialect : _DialectLike = ..., ** fmtparams : Any ) -> _reader : ...
42
46
def register_dialect (name : str , dialect : Any = ..., ** fmtparams : Any ) -> None : ...
43
47
def unregister_dialect (name : str ) -> None : ...
0 commit comments