File tree Expand file tree Collapse file tree 4 files changed +22
-14
lines changed
Expand file tree Collapse file tree 4 files changed +22
-14
lines changed Original file line number Diff line number Diff line change 99from typing import TYPE_CHECKING
1010from typing import Any
1111from typing import Mapping
12- from typing import Type
1312from typing import TypeVar
1413from typing import Union
1514
15+ import _csv
16+
1617from clevercsv .dialect import SimpleDialect
1718
1819AnyPath = Union [str , bytes , "os.PathLike[str]" , "os.PathLike[bytes]" ]
1920StrPath = Union [str , "os.PathLike[str]" ]
2021_OpenFile = Union [AnyPath , int ]
2122_DictRow = Mapping [str , Any ]
22- _DialectLike = Union [str , csv .Dialect , Type [csv .Dialect ], SimpleDialect ]
23+ _DialectLike = Union [
24+ str ,
25+ csv .Dialect ,
26+ _csv .Dialect ,
27+ type [_csv .Dialect ],
28+ SimpleDialect ,
29+ ]
2330_T = TypeVar ("_T" )
2431
2532if sys .version_info >= (3 , 8 ):
Original file line number Diff line number Diff line change 1616from typing import Dict
1717from typing import Optional
1818from typing import Tuple
19- from typing import Type
2019from typing import Union
2120
21+ import _csv
22+
2223excel = csv .excel
2324excel_tab = csv .excel_tab
2425unix_dialect = csv .unix_dialect
@@ -84,7 +85,7 @@ def validate(self) -> None:
8485
8586 @classmethod
8687 def from_dict (
87- cls : Type ["SimpleDialect" ], d : Dict [str , Any ]
88+ cls : type ["SimpleDialect" ], d : Dict [str , Any ]
8889 ) -> "SimpleDialect" :
8990 dialect = cls (
9091 d ["delimiter" ], d ["quotechar" ], d ["escapechar" ], strict = d ["strict" ]
@@ -93,7 +94,7 @@ def from_dict(
9394
9495 @classmethod
9596 def from_csv_dialect (
96- cls : Type ["SimpleDialect" ], d : csv .Dialect
97+ cls : type ["SimpleDialect" ], d : _csv . Dialect | csv .Dialect
9798 ) -> "SimpleDialect" :
9899 delimiter = "" if d .delimiter is None else d .delimiter
99100 quotechar = "" if d .quoting == csv .QUOTE_NONE else d .quotechar
@@ -132,7 +133,7 @@ def serialize(self) -> str:
132133 return json .dumps (self .to_dict ())
133134
134135 @classmethod
135- def deserialize (cls : Type ["SimpleDialect" ], obj : str ) -> "SimpleDialect" :
136+ def deserialize (cls : type ["SimpleDialect" ], obj : str ) -> "SimpleDialect" :
136137 """Deserialize dialect from a JSON object"""
137138 return cls .from_dict (json .loads (obj ))
138139
Original file line number Diff line number Diff line change 1515from typing import TYPE_CHECKING
1616from typing import Any
1717from typing import Iterable
18- from typing import Type
18+
19+ import _csv
1920
2021if TYPE_CHECKING :
2122 from clevercsv ._types import SupportsWrite
@@ -45,18 +46,18 @@ def __init__(
4546 ** fmtparams : Any ,
4647 ) -> None :
4748 self .original_dialect = dialect
48- self .dialect : Type [ csv .Dialect ] = self ._make_python_dialect (
49+ self .dialect : type [ _csv .Dialect ] = self ._make_python_dialect (
4950 dialect , ** fmtparams
5051 )
51- self ._writer = csv .writer (csvfile , dialect = self .dialect )
52+ self ._writer = _csv .writer (csvfile , dialect = self .dialect )
5253
5354 def _make_python_dialect (
5455 self , dialect : _DialectLike , ** fmtparams : Any
55- ) -> Type [ csv .Dialect ]:
56+ ) -> type [ _csv .Dialect ]:
5657 d : _DialectLike = ""
5758 if isinstance (dialect , str ):
58- d = csv .get_dialect (dialect )
59- elif isinstance (dialect , csv .Dialect ):
59+ d = _csv .get_dialect (dialect )
60+ elif isinstance (dialect , _csv .Dialect ):
6061 d = dialect
6162 elif isinstance (dialect , SimpleDialect ):
6263 d = dialect .to_csv_dialect ()
Original file line number Diff line number Diff line change 1414
1515from typing import Any
1616from typing import Iterable
17- from typing import Type
1817
1918import clevercsv
2019
@@ -32,7 +31,7 @@ def _write_test(
3231 self .assertEqual (fp .read (), expect + writer .dialect .lineterminator )
3332
3433 def _write_error_test (
35- self , exc : Type [Exception ], fields : Any , ** kwargs : Any
34+ self , exc : type [Exception ], fields : Any , ** kwargs : Any
3635 ) -> None :
3736 with tempfile .TemporaryFile ("w+" , newline = "" , prefix = "ccsv_" ) as fp :
3837 writer = clevercsv .writer (fp , ** kwargs )
You can’t perform that action at this time.
0 commit comments