Skip to content

Commit 5836a05

Browse files
committed
Linting.
1 parent 91b0e22 commit 5836a05

File tree

7 files changed

+31
-16
lines changed

7 files changed

+31
-16
lines changed

domdf_python_tools/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
_T = TypeVar("_T")
6868

69-
class nullcontext(ContextManager):
69+
class nullcontext(ContextManager[Optional[_T]]):
7070
"""
7171
Context manager that does no additional processing.
7272

domdf_python_tools/pagesizes/classes.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,12 @@ class PageSize(BaseSize):
215215

216216
__slots__: List[str] = []
217217

218-
def __new__(cls, width: AnyNumber, height: AnyNumber, unit: AnyNumber = pt):
218+
def __new__(
219+
cls,
220+
width: AnyNumber,
221+
height: AnyNumber,
222+
unit: AnyNumber = pt, # pylint: disable=used-before-assignment
223+
):
219224
"""
220225
Create a new :class:`~domdf_python_tools.pagesizes.classes.PageSize` object.
221226

domdf_python_tools/pretty_print.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,34 @@ def _make_open(self, char: str, indent: int, obj):
105105
else:
106106
the_indent = ' ' * (indent + self._indent_per_level)
107107

108-
if len(obj) and not self._compact: # type: ignore
108+
if obj and not self._compact: # type: ignore
109109
return f"{char}\n{the_indent}"
110110
else:
111111
return char
112112

113113
def _make_close(self, char: str, indent: int, obj):
114-
if len(obj) and not self._compact: # type: ignore
114+
if obj and not self._compact: # type: ignore
115115
return f",\n{' ' * (indent + self._indent_per_level)}{char}"
116116
else:
117117
return char
118118

119-
def _pprint_dict(self, object, stream, indent, allowance, context, level): # noqa: A002
119+
def _pprint_dict(
120+
self,
121+
object, # noqa: A002 # pylint: disable=redefined-builtin
122+
stream,
123+
indent,
124+
allowance,
125+
context,
126+
level,
127+
):
120128
obj = object
121129
write = stream.write
122130
write(self._make_open('{', indent, obj))
123131

124132
if self._indent_per_level > 1:
125133
write((self._indent_per_level - 1) * ' ')
126134

127-
if len(obj):
135+
if obj:
128136
self._format_dict_items( # type: ignore
129137
obj.items(),
130138
stream,
@@ -154,9 +162,10 @@ def _pprint_tuple(self, obj, stream, indent, allowance, context, level):
154162
_dispatch[tuple.__repr__] = _pprint_tuple
155163

156164
def _pprint_set(self, obj, stream, indent, allowance, context, level):
157-
if not len(obj):
165+
if not obj:
158166
stream.write(repr(obj))
159167
return
168+
160169
typ = obj.__class__
161170
if typ is set:
162171
stream.write(self._make_open('{', indent, obj))
@@ -165,6 +174,7 @@ def _pprint_set(self, obj, stream, indent, allowance, context, level):
165174
stream.write(typ.__name__ + f"({{\n{' ' * (indent + self._indent_per_level + len(typ.__name__) + 1)}")
166175
endchar = f",\n{' ' * (indent + self._indent_per_level + len(typ.__name__) + 1)}}})"
167176
indent += len(typ.__name__) + 1
177+
168178
obj = sorted(obj, key=_safe_key)
169179
self._format_items(obj, stream, indent, allowance + len(endchar), context, level)
170180
stream.write(endchar)
@@ -205,7 +215,7 @@ def format_attributes(self, obj: Attributes):
205215
if self._indent_per_level > 1:
206216
stream.write((self._indent_per_level - 1) * ' ')
207217

208-
if len(obj):
218+
if obj:
209219
self._format_attribute_items(list(obj), stream, 0, 0 + 1, context, 1)
210220
stream.write(f"\n{self._indent_per_level * ' '})")
211221

domdf_python_tools/stringlist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ def __setitem__(self, index: Union[int, slice], line: Union[String, Iterable[Str
238238
self.insert(index, line)
239239

240240
elif isinstance(index, slice):
241-
for line, index in zip(
241+
for line, idx in zip( # pylint: disable=redefined-argument-from-local
242242
reversed(line), # type: ignore
243243
reversed(range(index.start or 0, index.stop + 1, index.step or 1)),
244244
):
245-
self[index] = line
245+
self[idx] = line
246246

247247
@overload
248248
def __getitem__(self, index: int) -> str:
@@ -461,4 +461,4 @@ class DelimitedList(List[_S]):
461461
"""
462462

463463
def __format__(self, format_spec: str) -> str:
464-
return format_spec.join([str(x) for x in self])
464+
return format_spec.join([str(x) for x in self]) # pylint: disable=not-an-iterable

tests/test_dates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_utc_offset_no_pytz():
145145
ImportError,
146146
match=r"'get_utc_offset' requires pytz \(.*\), but it could not be imported",
147147
):
148-
dates.get_utc_offset
148+
dates.get_utc_offset # pylint: disable=pointless-statement
149149

150150
with pytest.raises(
151151
ImportError,

tests/test_paths_stdlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,9 @@ def test_pickling_common(BASE):
595595
def test_concrete_class():
596596
p = PathPlus('a')
597597
if os.name == "nt":
598-
assert type(p) is WindowsPathPlus
598+
assert type(p) is WindowsPathPlus # pylint: disable=unidiomatic-typecheck
599599
else:
600-
assert type(p) is PosixPathPlus
600+
assert type(p) is PosixPathPlus # pylint: disable=unidiomatic-typecheck
601601

602602

603603
def test_unsupported_flavour():

tests/test_pretty_print.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __repr__(self):
115115
# Class Orderable is orderable with any type
116116
class Orderable:
117117

118-
def __init__(self, hash): # noqa A002
118+
def __init__(self, hash): # noqa A002 # pylint: disable=redefined-builtin
119119
self._hash = hash
120120

121121
def __lt__(self, other):
@@ -961,7 +961,7 @@ def test_user_string(self, value, width, expects):
961961

962962
class DottedPrettyPrinter(FancyPrinter):
963963

964-
def format(self, object, context, maxlevels, level): # noqa: A002,A003
964+
def format(self, object, context, maxlevels, level): # noqa: A002,A003 # pylint: disable=redefined-builtin
965965
if isinstance(object, str):
966966
if ' ' in object:
967967
return repr(object), 1, 0

0 commit comments

Comments
 (0)