Skip to content

Commit 7a836c0

Browse files
authored
Merge pull request #437 from fyntex/release/v0.20.0
Release v0.20.0
2 parents 0e887fb + ebcbfce commit 7a836c0

35 files changed

+559
-500
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.19.0
2+
current_version = 0.20.0
33
commit = True
44
tag = True
55
message = chore: Bump version from {current_version} to {new_version}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Dependency Review
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
dependency-review:
15+
name: Dependency Review
16+
runs-on: ubuntu-22.04
17+
18+
steps:
19+
- name: Check Out VCS Repository
20+
uses: actions/[email protected]
21+
22+
- name: Dependency Review
23+
uses: actions/[email protected]
24+
with:
25+
fail-on-severity: critical

.markdownlint.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ heading-style:
1212

1313
line-length:
1414
line_length: 100
15+
code_block_line_length: 200
16+
tables: false
1517

1618
no-duplicate-heading:
1719
allow_different_nesting: true
1820

21+
no-emphasis-as-heading: false
22+
1923
no-multiple-blanks:
2024
maximum: 2
2125

HISTORY.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# History
22

3+
## 0.20.0 (2023-02-10)
4+
5+
- (PR #403, 2023-01-05) chore(deps): Bump pyopenssl from 22.0.0 to 22.1.0
6+
- (PR #406, 2023-01-05) chore(deps-dev): Bump mypy from 0.982 to 0.991
7+
- (PR #405, 2023-01-23) chore(deps): Bump jsonschema from 4.16.0 to 4.17.3
8+
- (PR #422, 2023-01-26) Add GitHub Dependency Review
9+
- (PR #423, 2023-01-26) Improve GitHub Dependency Review
10+
- (PR #411, 2023-01-26) chore(deps-dev): Bump black from 22.10.0 to 22.12.0
11+
- (PR #425, 2023-01-27) Update Markdownlint configuration
12+
- (PR #410, 2023-02-03) chore(deps): Bump pydantic from 1.10.2 to 1.10.4
13+
- (PR #433, 2023-02-03) Improve type checking
14+
- (PR #434, 2023-02-03) Improve type checking
15+
- (PR #424, 2023-02-06) chore(deps-dev): Bump coverage from 6.5.0 to 7.1.0
16+
- (PR #414, 2023-02-06) chore(deps): Bump lxml from 4.9.1 to 4.9.2
17+
- (PR #420, 2023-02-06) chore(deps): Bump pytz from 2022.6 to 2022.7.1
18+
- (PR #431, 2023-02-06) chore(deps): Bump pyopenssl from 22.1.0 to 23.0.0
19+
- (PR #436, 2023-02-08) chore(deps): Bump cryptography from 38.0.4 to 39.0.1
20+
- (PR #435, 2023-02-08) chore(deps): Bump django from 3.2.16 to 3.2.17
21+
- (PR #426, 2023-02-08) chore(deps): Bump marshmallow from 2.21.0 to 3.19.0
22+
323
## 0.19.0 (2023-01-05)
424

525
- (PR #398, 2022-11-23) fix: Fix Dependabot error pip.….Error: Constraints cannot have extras

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ install-deps-dev: ## Install dependencies for development
5858

5959
lint: ## run tools for code style analysis, static type check, etc
6060
flake8 --config=setup.cfg cl_sii scripts tests
61-
mypy --config-file setup.cfg cl_sii scripts
61+
mypy
6262
isort --check-only .
6363
$(BLACK) --check .
6464

cl_sii/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"""
66

77

8-
__version__ = '0.19.0'
8+
__version__ = '0.20.0'

cl_sii/extras/mm_fields.py

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
(for serializers)
55
66
"""
7+
from __future__ import annotations
8+
9+
710
try:
811
import marshmallow
912
except ImportError as exc: # pragma: no cover
1013
raise ImportError("Package 'marshmallow' is required to use this module.") from exc
1114

1215
import datetime
13-
from typing import Optional
16+
from typing import Any, Mapping, Optional
1417

1518
import marshmallow.fields
1619

@@ -46,13 +49,18 @@ class RutField(marshmallow.fields.Field):
4649

4750
default_error_messages = {
4851
'invalid': 'Not a syntactically valid RUT.',
52+
'type': 'Invalid type.',
4953
}
5054

51-
def _serialize(self, value: Optional[object], attr: str, obj: object) -> Optional[str]:
55+
def _serialize(
56+
self, value: Optional[object], attr: str | None, obj: object, **kwargs: Any
57+
) -> Optional[str]:
5258
validated = self._validated(value)
5359
return validated.canonical if validated is not None else None
5460

55-
def _deserialize(self, value: str, attr: str, data: dict) -> Optional[Rut]:
61+
def _deserialize(
62+
self, value: str, attr: str | None, data: Mapping[str, Any] | None, **kwargs: Any
63+
) -> Optional[Rut]:
5664
return self._validated(value)
5765

5866
def _validated(self, value: Optional[object]) -> Optional[Rut]:
@@ -61,10 +69,10 @@ def _validated(self, value: Optional[object]) -> Optional[Rut]:
6169
else:
6270
try:
6371
validated = Rut(value, validate_dv=False) # type: ignore
64-
except TypeError:
65-
self.fail('type')
66-
except ValueError:
67-
self.fail('invalid')
72+
except TypeError as exc:
73+
raise self.make_error('type') from exc
74+
except ValueError as exc:
75+
raise self.make_error('invalid') from exc
6876
return validated
6977

7078

@@ -89,13 +97,18 @@ class TipoDteField(marshmallow.fields.Field):
8997

9098
default_error_messages = {
9199
'invalid': 'Not a valid Tipo DTE.',
100+
'type': 'Invalid type.',
92101
}
93102

94-
def _serialize(self, value: Optional[object], attr: str, obj: object) -> Optional[int]:
103+
def _serialize(
104+
self, value: Optional[object], attr: str | None, obj: object, **kwargs: Any
105+
) -> Optional[int]:
95106
validated: Optional[TipoDte] = self._validated(value)
96107
return validated.value if validated is not None else None
97108

98-
def _deserialize(self, value: object, attr: str, data: dict) -> Optional[TipoDte]:
109+
def _deserialize(
110+
self, value: object, attr: str | None, data: Mapping[str, Any] | None, **kwargs: Any
111+
) -> Optional[TipoDte]:
99112
return self._validated(value)
100113

101114
def _validated(self, value: Optional[object]) -> Optional[TipoDte]:
@@ -104,21 +117,21 @@ def _validated(self, value: Optional[object]) -> Optional[TipoDte]:
104117
else:
105118
if isinstance(value, bool):
106119
# is value is bool, `isinstance(value, int)` is True and `int(value)` works!
107-
self.fail('type')
120+
raise self.make_error('type')
108121
try:
109122
value = int(value) # type: ignore
110-
except ValueError:
123+
except ValueError as exc:
111124
# `int('x')` raises 'ValueError', not 'TypeError'
112-
self.fail('type')
113-
except TypeError:
125+
raise self.make_error('type') from exc
126+
except TypeError as exc:
114127
# `int(date(2018, 10, 10))` raises 'TypeError', unlike `int('x')`
115-
self.fail('type')
128+
raise self.make_error('type') from exc
116129

117130
try:
118131
validated = TipoDte(value) # type: ignore
119-
except ValueError:
132+
except ValueError as exc:
120133
# TipoDte('x') raises 'ValueError', not 'TypeError'
121-
self.fail('invalid')
134+
raise self.make_error('invalid') from exc
122135
return validated
123136

124137

@@ -142,13 +155,18 @@ class RcvTipoDoctoField(marshmallow.fields.Field):
142155

143156
default_error_messages = {
144157
'invalid': "Not a valid RCV's Tipo de Documento.",
158+
'type': "Invalid type.",
145159
}
146160

147-
def _serialize(self, value: Optional[object], attr: str, obj: object) -> Optional[int]:
161+
def _serialize(
162+
self, value: Optional[object], attr: str | None, obj: object, **kwargs: Any
163+
) -> Optional[int]:
148164
validated: Optional[RcvTipoDocto] = self._validated(value)
149165
return validated.value if validated is not None else None
150166

151-
def _deserialize(self, value: object, attr: str, data: dict) -> Optional[RcvTipoDocto]:
167+
def _deserialize(
168+
self, value: object, attr: str | None, data: Mapping[str, Any] | None, **kwargs: Any
169+
) -> Optional[RcvTipoDocto]:
152170
return self._validated(value)
153171

154172
def _validated(self, value: Optional[object]) -> Optional[RcvTipoDocto]:
@@ -157,21 +175,21 @@ def _validated(self, value: Optional[object]) -> Optional[RcvTipoDocto]:
157175
else:
158176
if isinstance(value, bool):
159177
# is value is bool, `isinstance(value, int)` is True and `int(value)` works!
160-
self.fail('type')
178+
raise self.make_error('type')
161179
try:
162180
value = int(value) # type: ignore
163-
except ValueError:
181+
except ValueError as exc:
164182
# `int('x')` raises 'ValueError', not 'TypeError'
165-
self.fail('type')
166-
except TypeError:
183+
raise self.make_error('type') from exc
184+
except TypeError as exc:
167185
# `int(date(2018, 10, 10))` raises 'TypeError', unlike `int('x')`
168-
self.fail('type')
186+
raise self.make_error('type') from exc
169187

170188
try:
171189
validated = RcvTipoDocto(value) # type: ignore
172-
except ValueError:
190+
except ValueError as exc:
173191
# RcvTipoDocto('x') raises 'ValueError', not 'TypeError'
174-
self.fail('invalid')
192+
raise self.make_error('invalid') from exc
175193
return validated
176194

177195

@@ -186,14 +204,19 @@ class RcvPeriodoTributarioField(marshmallow.fields.Field):
186204

187205
default_error_messages = {
188206
'invalid': "Not a valid RCV Periodo Tributario.",
207+
'type': "Invalid type.",
189208
}
190209
_string_format = '%Y-%m' # Example: '2019-12'
191210

192-
def _serialize(self, value: Optional[object], attr: str, obj: object) -> Optional[str]:
211+
def _serialize(
212+
self, value: Optional[object], attr: str | None, obj: object, **kwargs: Any
213+
) -> Optional[str]:
193214
validated: Optional[RcvPeriodoTributario] = self._validated(value)
194215
return validated.as_date().strftime(self._string_format) if validated is not None else None
195216

196-
def _deserialize(self, value: object, attr: str, data: dict) -> Optional[RcvPeriodoTributario]:
217+
def _deserialize(
218+
self, value: object, attr: str | None, data: Mapping[str, Any] | None, **kwargs: Any
219+
) -> Optional[RcvPeriodoTributario]:
197220
return self._validated(value)
198221

199222
def _validated(self, value: Optional[object]) -> Optional[RcvPeriodoTributario]:
@@ -203,10 +226,10 @@ def _validated(self, value: Optional[object]) -> Optional[RcvPeriodoTributario]:
203226
try:
204227
value = datetime.datetime.strptime(value, self._string_format) # type: ignore
205228
value = value.date()
206-
except ValueError:
207-
self.fail('invalid')
208-
except TypeError:
209-
self.fail('type')
229+
except ValueError as exc:
230+
raise self.make_error('invalid') from exc
231+
except TypeError as exc:
232+
raise self.make_error('type') from exc
210233

211234
validated = RcvPeriodoTributario.from_date(value) # type: ignore
212235

cl_sii/libs/csv_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import csv
2-
from typing import IO, Sequence, Type, Union
2+
from typing import IO, Optional, Sequence, Type, Union
33

44

55
def create_csv_dict_reader(
66
text_stream: IO[str],
77
csv_dialect: Type[csv.Dialect],
88
row_dict_extra_fields_key: Union[str, None] = None,
99
expected_fields_strict: bool = True,
10-
expected_field_names: Sequence[str] = None,
10+
expected_field_names: Optional[Sequence[str]] = None,
1111
) -> csv.DictReader:
1212
"""
1313
Create a CSV dict reader with custom options.

cl_sii/libs/mm_utils.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
from datetime import date, datetime
2-
from typing import Any, Union
4+
from typing import Any, Mapping, Optional, Union
35

46
import marshmallow
57
import marshmallow.fields
@@ -22,10 +24,6 @@ def validate_no_unexpected_input_fields(
2224
Usage::
2325
2426
class MySchema(marshmallow.Schema):
25-
26-
class Meta:
27-
strict = True
28-
2927
folio = marshmallow.fields.Integer()
3028
3129
@marshmallow.validates_schema(pass_original=True)
@@ -36,7 +34,7 @@ def validate_schema(self, data: dict, original_data: dict) -> None:
3634
# Original inspiration from
3735
# https://marshmallow.readthedocs.io/en/2.x-line/extending.html#validating-original-input-data
3836
fields_name_or_load_from = {
39-
field.name if field.load_from is None else field.load_from
37+
field.name if field.data_key is None else field.data_key
4038
for field_key, field in schema.fields.items()
4139
}
4240
unexpected_input_fields = set(original_data) - fields_name_or_load_from
@@ -83,7 +81,7 @@ class CustomMarshmallowDateField(marshmallow.fields.Field):
8381
'format': '"{input}" cannot be formatted as a date.',
8482
}
8583

86-
def __init__(self, format: str = None, **kwargs: Any) -> None:
84+
def __init__(self, format: Optional[str] = None, **kwargs: Any) -> None:
8785
"""Constructor.
8886
8987
:param format: Either ``"iso"`` (for ISO-8601) or a date format str.
@@ -98,41 +96,45 @@ def __init__(self, format: str = None, **kwargs: Any) -> None:
9896
# TODO: for 'marshmallow 3', rename 'dateformat' to 'datetimeformat'.
9997
self.dateformat = format
10098

101-
def _add_to_schema(self, field_name: str, schema: marshmallow.Schema) -> None:
102-
super()._add_to_schema(field_name, schema)
99+
def _bind_to_schema(self, field_name: str, schema: marshmallow.Schema) -> None:
100+
super()._bind_to_schema(field_name, schema)
103101
self.dateformat = self.dateformat or schema.opts.dateformat
104102

105-
def _serialize(self, value: date, attr: str, obj: object) -> Union[str, None]:
103+
def _serialize(
104+
self, value: date, attr: str | None, obj: object, **kwargs: Any
105+
) -> Union[str, None]:
106106
if value is None:
107107
return None
108108
self.dateformat = self.dateformat or self.DEFAULT_FORMAT
109109
format_func = self.DATEFORMAT_SERIALIZATION_FUNCS.get(self.dateformat, None)
110110
if format_func:
111111
try:
112112
date_str = format_func(value)
113-
except (AttributeError, ValueError):
114-
self.fail('format', input=value)
113+
except (AttributeError, ValueError) as exc:
114+
raise self.make_error('format', input=value) from exc
115115
else:
116116
date_str = value.strftime(self.dateformat)
117117

118118
return date_str
119119

120-
def _deserialize(self, value: str, attr: str, data: dict) -> date:
120+
def _deserialize(
121+
self, value: str, attr: str | None, data: Mapping[str, Any] | None, **kwargs: Any
122+
) -> date:
121123
if not value: # Falsy values, e.g. '', None, [] are not valid
122-
self.fail('invalid')
124+
raise self.make_error('invalid')
123125
self.dateformat = self.dateformat or self.DEFAULT_FORMAT
124126
func = self.DATEFORMAT_DESERIALIZATION_FUNCS.get(self.dateformat)
125127
if func:
126128
try:
127129
date_value = func(value) # type: date
128-
except (TypeError, AttributeError, ValueError):
129-
self.fail('invalid')
130+
except (TypeError, AttributeError, ValueError) as exc:
131+
raise self.make_error('invalid') from exc
130132
elif self.dateformat:
131133
try:
132134
date_value = datetime.strptime(value, self.dateformat).date()
133-
except (TypeError, AttributeError, ValueError):
134-
self.fail('invalid')
135+
except (TypeError, AttributeError, ValueError) as exc:
136+
raise self.make_error('invalid') from exc
135137
else:
136-
self.fail('invalid')
138+
raise self.make_error('invalid')
137139

138140
return date_value

0 commit comments

Comments
 (0)