Skip to content

Commit 16b2e81

Browse files
committed
lint
1 parent ee3b987 commit 16b2e81

File tree

6 files changed

+163
-97
lines changed

6 files changed

+163
-97
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ignore_errors = True
3232
directory = coverage_html_report
3333

3434
[pylint]
35-
disable = R0903, W0613, C0111, W0703, C0103, W0212
35+
disable = R0903, W0613, C0111, W0703, C0103, W0212, R0903
3636
ignore-docstrings = yes
3737
output-format = colorized
3838
fail-under = 9

typedpy/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,3 @@
7979
)
8080

8181
from typedpy.errors import standard_readable_error_for_typedpy_exception, ErrorInfo
82-

typedpy/errors.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class ErrorInfo(ImmutableStructure):
1616
"int": "an integer number",
1717
"str": "a text value",
1818
"float": "a decimal number",
19-
"list": "an array"
19+
"list": "an array",
2020
}
2121

22-
_expected_class_pattern = re.compile("^Expected\s<class '(.*)'>$")
22+
_expected_class_pattern = re.compile(r"^Expected\s<class '(.*)'>$")
2323

2424

2525
def _transform_class_to_readable(problem: str):
@@ -41,37 +41,41 @@ def standard_readable_error_for_typedpy_exception(e: Exception, top_level=True):
4141
else:
4242
try:
4343
errs = json.loads(err_message)
44-
return [_standard_readable_error_for_typedpy_exception_internal(e) for e in errs]
44+
return [
45+
_standard_readable_error_for_typedpy_exception_internal(e) for e in errs
46+
]
4547
except JSONDecodeError as e:
4648
if not top_level:
4749
raise e
48-
return [_standard_readable_error_for_typedpy_exception_internal(err_message)]
50+
return [
51+
_standard_readable_error_for_typedpy_exception_internal(err_message)
52+
]
4953

5054

5155
def _standard_readable_error_for_typedpy_exception_internal(err_message: str):
5256
def try_expand(problem_str):
5357
if not Structure.failing_fast():
5458
try:
5559
return standard_readable_error_for_typedpy_exception(
56-
Exception(problem_str),
57-
top_level=False)
60+
Exception(problem_str), top_level=False
61+
)
5862
except Exception:
5963
pass
6064
return problem_str
6165

6266
match = _pattern_for_typepy_validation_1.match(err_message)
6367
if match:
6468
problem = _transform_class_to_readable(match.group(3))
65-
return ErrorInfo(value=match.group(2),
66-
problem=try_expand(problem),
67-
field=match.group(1))
69+
return ErrorInfo(
70+
value=match.group(2), problem=try_expand(problem), field=match.group(1)
71+
)
6872

6973
match = _pattern_for_typepy_validation_2.match(err_message)
7074
if match:
7175
problem = _transform_class_to_readable(match.group(2))
72-
return ErrorInfo(value=match.group(3),
73-
problem=try_expand(problem),
74-
field=match.group(1))
76+
return ErrorInfo(
77+
value=match.group(3), problem=try_expand(problem), field=match.group(1)
78+
)
7579

7680
match = _pattern_for_typepy_validation_3.match(err_message)
7781
if match:

typedpy/extfields.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Additional types of fields: datefield, datetime, timestring, DateString,
3+
Hostname, etc.
4+
"""
15
import json
26
from datetime import datetime, date
37
import re
@@ -32,7 +36,11 @@ def __set__(self, instance, value):
3236
):
3337
super().__set__(instance, value)
3438
else:
35-
raise ValueError("{}: Got {}; wrong format for IP version 4".format(self._name, wrap_val(value)))
39+
raise ValueError(
40+
"{}: Got {}; wrong format for IP version 4".format(
41+
self._name, wrap_val(value)
42+
)
43+
)
3644

3745

3846
class HostName(String):
@@ -44,11 +52,19 @@ class HostName(String):
4452

4553
def __set__(self, instance, value):
4654
if not HostName._host_name_re.match(value):
47-
raise ValueError("{}: Got {}; wrong format for hostname".format(self._name, wrap_val(value)))
55+
raise ValueError(
56+
"{}: Got {}; wrong format for hostname".format(
57+
self._name, wrap_val(value)
58+
)
59+
)
4860
components = value.split(".")
4961
for component in components:
5062
if len(component) > 63:
51-
raise ValueError("{}: Got {}; wrong format for hostname".format(self._name, wrap_val(value)))
63+
raise ValueError(
64+
"{}: Got {}; wrong format for hostname".format(
65+
self._name, wrap_val(value)
66+
)
67+
)
5268
super().__set__(instance, value)
5369

5470

@@ -73,7 +89,9 @@ def __set__(self, instance, value):
7389
try:
7490
datetime.strptime(value, self._format)
7591
except ValueError as ex:
76-
raise ValueError("{}: Got {}; {}".format(self._name, wrap_val(value), ex.args[0]))
92+
raise ValueError(
93+
"{}: Got {}; {}".format(self._name, wrap_val(value), ex.args[0])
94+
)
7795

7896

7997
class TimeString(TypedField):
@@ -88,7 +106,9 @@ def __set__(self, instance, value):
88106
try:
89107
datetime.strptime(value, "%H:%M:%S")
90108
except ValueError as ex:
91-
raise ValueError("{}: Got {}; {}".format(self._name, wrap_val(value), ex.args[0]))
109+
raise ValueError(
110+
"{}: Got {}; {}".format(self._name, wrap_val(value), ex.args[0])
111+
)
92112

93113

94114
class DateField(SerializableField):
@@ -125,7 +145,9 @@ def deserialize(self, value):
125145
try:
126146
return datetime.strptime(value, self._date_format).date()
127147
except ValueError as ex:
128-
raise ValueError("{}: Got {}; {}".format(self._name, wrap_val(value), str(ex))) from ex
148+
raise ValueError(
149+
"{}: Got {}; {}".format(self._name, wrap_val(value), str(ex))
150+
) from ex
129151

130152
def __set__(self, instance, value):
131153
if isinstance(value, str):
@@ -136,7 +158,11 @@ def __set__(self, instance, value):
136158
elif isinstance(value, date):
137159
super().__set__(instance, value)
138160
else:
139-
raise TypeError("{}: Got {}; Expected date, datetime, or str".format(self._name, wrap_val(value)))
161+
raise TypeError(
162+
"{}: Got {}; Expected date, datetime, or str".format(
163+
self._name, wrap_val(value)
164+
)
165+
)
140166

141167

142168
class DateTime(SerializableField):
@@ -172,7 +198,9 @@ def deserialize(self, value):
172198
try:
173199
return datetime.strptime(value, self._datetime_format)
174200
except ValueError as ex:
175-
raise ValueError("{}: Got {}; {}".format(self._name, wrap_val(value), str(ex))) from ex
201+
raise ValueError(
202+
"{}: Got {}; {}".format(self._name, wrap_val(value), str(ex))
203+
) from ex
176204

177205
def __set__(self, instance, value):
178206
if isinstance(value, str):
@@ -181,4 +209,8 @@ def __set__(self, instance, value):
181209
elif isinstance(value, datetime):
182210
super().__set__(instance, value)
183211
else:
184-
raise TypeError("{}: Got {}; Expected datetime or str".format(self._name, wrap_val(value)))
212+
raise TypeError(
213+
"{}: Got {}; Expected datetime or str".format(
214+
self._name, wrap_val(value)
215+
)
216+
)

typedpy/fields.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class for it.
7070
)
7171
7272
73-
Important: Since Typedpy dynamically creates an internal class for it, this field cannot be pickled!
73+
Important: Since Typedpy dynamically creates an internal class for it, this
74+
field cannot be pickled!
7475
"""
7576

7677
counter = 0
@@ -83,7 +84,7 @@ def __init__(self, **kwargs):
8384
super().__init__(kwargs)
8485

8586
def __set__(self, instance, value):
86-
if not (isinstance(value, (dict, Structure))):
87+
if not isinstance(value, (dict, Structure)):
8788
raise TypeError(
8889
"{}: Expected a dictionary or Structure; got {}".format(
8990
self._name, value
@@ -203,7 +204,8 @@ def _validate(self, value):
203204

204205
class DecimalNumber(Number, SerializableField):
205206
"""
206-
An extension of :class:`Number` for a Decimal. Accepts anything that can be converted to a Decimal.
207+
An extension of :class:`Number` for a Decimal. Accepts anything that can be
208+
converted to a Decimal.
207209
It converts the value to a Decimal.
208210
"""
209211

@@ -221,8 +223,6 @@ def serialize(self, value):
221223
return float(value)
222224

223225

224-
225-
226226
class StructureClass(TypedField):
227227
_ty = StructMeta
228228

@@ -285,7 +285,8 @@ def __set__(self, instance, value):
285285

286286
class Function(Field):
287287
"""
288-
A function or method. Note that this can't be any callable (it can't be a class, for example), but a real function
288+
A function or method. Note that this can't be any callable (it can't be a class,
289+
for example), but a real function
289290
"""
290291

291292
_bound_method_type = type(Field().__init__)
@@ -364,7 +365,9 @@ class Positive(Number):
364365

365366
def __set__(self, instance, value):
366367
if value <= 0:
367-
raise ValueError("{}: Got {}; Expected a positive number".format(self._name, value))
368+
raise ValueError(
369+
"{}: Got {}; Expected a positive number".format(self._name, value)
370+
)
368371
super().__set__(instance, value)
369372

370373

@@ -1308,15 +1311,22 @@ def _validate(self, value):
13081311
enum_values = [r.name for r in self._enum_class]
13091312
if len(enum_values) < 11:
13101313
raise ValueError(
1311-
"{}: Got {}; Expected one of: {}".format(self._name, value, ", ".join(enum_values))
1314+
"{}: Got {}; Expected one of: {}".format(
1315+
self._name, value, ", ".join(enum_values)
1316+
)
13121317
)
13131318
raise ValueError(
1314-
"{}: Got {}; Expected a value of {}".format(self._name, value, self._enum_class)
1319+
"{}: Got {}; Expected a value of {}".format(
1320+
self._name, value, self._enum_class
1321+
)
13151322
)
13161323

13171324
elif value not in self.values:
1318-
raise ValueError("{}: Got {}; Expected one of {}".format(
1319-
self._name, value, ', '.join([str(v) for v in self.values])))
1325+
raise ValueError(
1326+
"{}: Got {}; Expected one of {}".format(
1327+
self._name, value, ", ".join([str(v) for v in self.values])
1328+
)
1329+
)
13201330

13211331
def __set__(self, instance, value):
13221332
self._validate(value)
@@ -1362,7 +1372,11 @@ def __init__(self, *args, maxlen, **kwargs):
13621372

13631373
def __set__(self, instance, value):
13641374
if len(value) > self.maxlen:
1365-
raise ValueError("{}: Got {}; Expected a length up to {}".format(self._name, value, self.maxlen))
1375+
raise ValueError(
1376+
"{}: Got {}; Expected a length up to {}".format(
1377+
self._name, value, self.maxlen
1378+
)
1379+
)
13661380
super().__set__(instance, value)
13671381

13681382

@@ -1636,7 +1650,7 @@ class ImmutableInteger(ImmutableField, Integer):
16361650
pass
16371651

16381652

1639-
class ImmutableFloat(ImmutableField, Float):
1653+
class ImmutableFloat(ImmutableField, Float): # pylint: disable=
16401654
"""
16411655
An immutable version of :class:`Float`
16421656
"""

0 commit comments

Comments
 (0)