Skip to content

Commit d9f21d8

Browse files
committed
rename cls to klass to avoid name collusion with the real cls arg used in classmethods
1 parent 6bbf50a commit d9f21d8

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

dataclass_csv/dataclass_reader.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class DataclassReader(Generic[T]):
6666
def __init__(
6767
self,
6868
f: Any,
69-
cls: Type[T],
69+
klass: Type[T],
7070
fieldnames: Optional[Sequence[str]] = None,
7171
restkey: Optional[str] = None,
7272
restval: Optional[Any] = None,
@@ -78,10 +78,10 @@ def __init__(
7878
if not f:
7979
raise ValueError("The f argument is required.")
8080

81-
if cls is None or not dataclasses.is_dataclass(cls):
82-
raise ValueError("cls argument needs to be a dataclass.")
81+
if klass is None or not dataclasses.is_dataclass(klass):
82+
raise ValueError("klass argument needs to be a dataclass.")
8383

84-
self._cls = cls
84+
self._cls = klass
8585
self._optional_fields = self._get_optional_fields()
8686
self._field_mapping: Dict[str, Dict[str, Any]] = {}
8787

@@ -94,7 +94,7 @@ def __init__(
9494
if validate_header:
9595
_verify_duplicate_header_items(self._reader.fieldnames)
9696

97-
self.type_hints = typing.get_type_hints(cls)
97+
self.type_hints = typing.get_type_hints(klass)
9898

9999
def _get_optional_fields(self):
100100
return [

dataclass_csv/dataclass_writer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def __init__(
99
self,
1010
f: Any,
1111
data: List[Any],
12-
cls: Type[object],
12+
klass: Type[object],
1313
dialect: str = "excel",
1414
**fmtparams: Any,
1515
):
@@ -19,14 +19,14 @@ def __init__(
1919
if not isinstance(data, list):
2020
raise ValueError("Invalid 'data' argument. It must be a list")
2121

22-
if not dataclasses.is_dataclass(cls):
23-
raise ValueError("Invalid 'cls' argument. It must be a dataclass")
22+
if not dataclasses.is_dataclass(klass):
23+
raise ValueError("Invalid 'klass' argument. It must be a dataclass")
2424

2525
self._data = data
26-
self._cls = cls
26+
self._cls = klass
2727
self._field_mapping: Dict[str, str] = dict()
2828

29-
self._fieldnames = [x.name for x in dataclasses.fields(cls)]
29+
self._fieldnames = [x.name for x in dataclasses.fields(klass)]
3030

3131
self._writer = csv.writer(f, dialect=dialect, **fmtparams)
3232

dataclass_csv/decorators.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def dateformat(date_format: str) -> Callable[[F], F]:
2323
if not date_format or not isinstance(date_format, str):
2424
raise ValueError("Invalid value for the date_format argument")
2525

26-
def func(cls):
27-
cls.__dateformat__ = date_format
28-
return cls
26+
def func(klass):
27+
klass.__dateformat__ = date_format
28+
return klass
2929

3030
return func
3131

@@ -47,9 +47,9 @@ def accept_whitespaces(_cls: Type[Any] = None) -> Callable[[F], F]:
4747
>>> brithday: datetime
4848
"""
4949

50-
def func(cls):
51-
cls.__accept_whitespaces__ = True
52-
return cls
50+
def func(klass):
51+
klass.__accept_whitespaces__ = True
52+
return klass
5353

5454
if _cls:
5555
return func(_cls)

0 commit comments

Comments
 (0)