Skip to content

Commit bf8ea76

Browse files
committed
Lint
1 parent de089e8 commit bf8ea76

31 files changed

+528
-472
lines changed

domdf_python_tools/bases.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181

8282
@prettify_docstrings
83-
class Dictable(Iterable[Tuple[str, _V]]):
83+
class Dictable(Iterable[Tuple[str, _V]]): # noqa: PRM002
8484
"""
8585
The basic structure of a class that can be converted into a dictionary.
8686
"""
@@ -119,7 +119,7 @@ def __deepcopy__(self, memodict={}):
119119
def __dict__(self): # type: ignore[override]
120120
return dict() # pragma: no cover (abc)
121121

122-
def __eq__(self, other) -> bool:
122+
def __eq__(self, other) -> bool: # noqa: MAN001
123123
if isinstance(other, self.__class__):
124124
return is_match_with(other.__dict__, self.__dict__)
125125

@@ -266,13 +266,18 @@ def __copy__(self):
266266
def append(self, item: _T) -> None:
267267
"""
268268
Append ``item`` to the end of the :class:`~.domdf_python_tools.bases.UserList`.
269+
270+
:param item:
269271
"""
270272

271273
self.data.append(item)
272274

273275
def insert(self, i: int, item: _T) -> None:
274276
"""
275277
Insert ``item`` at position ``i`` in the :class:`~.domdf_python_tools.bases.UserList`.
278+
279+
:param i:
280+
:param item:
276281
"""
277282

278283
self.data.insert(i, item)
@@ -281,6 +286,8 @@ def pop(self, i: int = -1) -> _T:
281286
"""
282287
Removes and returns the item at index ``i``.
283288
289+
:param i:
290+
284291
:raises IndexError: if list is empty or index is out of range.
285292
"""
286293

@@ -315,19 +322,19 @@ def copy(self: _S) -> _S:
315322

316323
return self.__class__(self)
317324

318-
def count(self, item: _T) -> int:
325+
def count(self, item: _T) -> int: # noqa: PRM002
319326
"""
320327
Returns the number of occurrences of ``item`` in the :class:`~.domdf_python_tools.bases.UserList`.
321328
"""
322329

323330
return self.data.count(item)
324331

325332
def index(self, item: _T, *args: Any) -> int:
326-
"""
333+
r"""
327334
Returns the index of the fist element matching ``item``.
328335
329336
:param item:
330-
:param args:
337+
:param \*args:
331338
332339
:raises ValueError: if the item is not present.
333340
"""
@@ -341,7 +348,7 @@ def reverse(self) -> None:
341348

342349
self.data.reverse()
343350

344-
def sort(self, *, key=None, reverse: bool = False) -> None:
351+
def sort(self, *, key=None, reverse: bool = False) -> None: # noqa: PRM002
345352
"""
346353
Sort the list in ascending order and return :py:obj:`None`.
347354
@@ -628,7 +635,7 @@ def replace(self: _LU, what: _T, with_: _T) -> _LU:
628635

629636
return self
630637

631-
def sort( # type: ignore[override]
638+
def sort( # type: ignore[override] # noqa: PRM002
632639
self: _LU,
633640
*,
634641
key=None,

domdf_python_tools/dates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def is_bst(the_date: Union[time.struct_time, datetime.date]) -> bool:
383383
'{word_join(_pytz_functions)}' require pytz (https://pypi.org/project/pytz/), but it could not be imported.
384384
385385
The error was: {e}.
386-
"""
386+
""",
387387
)
388388

389389
else:
@@ -394,7 +394,7 @@ class SelfWrapper(ModuleType):
394394
def __getattr__(self, name):
395395
if name in _pytz_functions:
396396
raise ImportError(
397-
f"{name!r} requires pytz (https://pypi.org/project/pytz/), but it could not be imported."
397+
f"{name!r} requires pytz (https://pypi.org/project/pytz/), but it could not be imported.",
398398
)
399399
else:
400400
return getattr(_actual_module, name)

domdf_python_tools/delegators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def _f(f: _C) -> _C:
8383
del to_params[param]
8484

8585
f.__signature__ = from_sig.replace( # type: ignore[attr-defined]
86-
parameters=[*from_params.values(), *to_params.values()]
87-
)
86+
parameters=[*from_params.values(), *to_params.values()],
87+
)
8888
f.__annotations__ = {**to_annotations, **from_annotations}
8989

9090
return f
@@ -121,8 +121,8 @@ def _f(f: _C) -> _C:
121121

122122
elif tuple(from_params.keys()) == ("self", "args", "kwargs"):
123123
f.__signature__ = from_sig.replace( # type: ignore[attr-defined]
124-
parameters=[from_params["self"], *to_sig.parameters.values()]
125-
)
124+
parameters=[from_params["self"], *to_sig.parameters.values()],
125+
)
126126

127127
copy_annotations(f)
128128

domdf_python_tools/import_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"discover_in_module",
5454
"discover_entry_points",
5555
"discover_entry_points_by_name",
56-
"iter_submodules"
56+
"iter_submodules",
5757
]
5858

5959

domdf_python_tools/pagesizes/classes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def from_pt(cls, size: Tuple[float, float]):
110110
def from_size(cls, size: Tuple[AnyNumber, AnyNumber]) -> "BaseSize":
111111
"""
112112
Create a :class:`~domdf_python_tools.pagesizes.classes.BaseSize` object from a tuple.
113+
114+
:param size:
113115
"""
114116

115117
return cls(*size)

domdf_python_tools/pagesizes/units.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# stdlib
4040
import math
4141
from decimal import ROUND_HALF_UP, Decimal
42-
from typing import SupportsFloat, Union
42+
from typing import NoReturn, SupportsFloat, Union
4343

4444
# this package
4545
from domdf_python_tools.doctools import prettify_docstrings
@@ -199,12 +199,12 @@ class Unit(float):
199199
name: str = "pt"
200200
_in_pt: float = 1
201201

202-
def __repr__(self):
202+
def __repr__(self) -> str:
203203
value = _rounders(float(self), "0.000")
204204
as_pt = _rounders(self.as_pt(), "0.000")
205205
return f"<Unit '{value} {self.name}': {as_pt}pt>"
206206

207-
def __str__(self):
207+
def __str__(self) -> str:
208208
value = _rounders(float(self), "0.000")
209209
as_pt = _rounders(self.as_pt(), "0.000")
210210
return f"<Unit '{value}\u205F{self.name}': {as_pt}pt>"
@@ -251,10 +251,10 @@ def __mod__(self, other: Union[float, "Unit"]) -> "Unit":
251251

252252
return self.__class__(super().__mod__(other))
253253

254-
def __pow__(self, power, modulo=None):
254+
def __pow__(self, power, modulo=None) -> NoReturn: # noqa: MAN001
255255
raise NotImplementedError("Powers are not supported for units.")
256256

257-
def __rtruediv__(self, other):
257+
def __rtruediv__(self, other) -> NoReturn: # noqa: MAN001
258258
raise NotImplementedError("Dividing by a unit is not allowed.")
259259

260260
__rdiv__ = __rtruediv__

domdf_python_tools/paths.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
"""
144144

145145

146-
def append(var: str, filename: PathLike, **kwargs) -> int:
146+
def append(var: str, filename: PathLike, **kwargs) -> int: # noqa: PRM002
147147
"""
148148
Append ``var`` to the file ``filename`` in the current directory.
149149
@@ -205,7 +205,7 @@ def copytree(
205205
return dst
206206

207207

208-
def delete(filename: PathLike, **kwargs):
208+
def delete(filename: PathLike, **kwargs): # noqa: PRM002
209209
"""
210210
Delete the file in the current directory.
211211
@@ -261,7 +261,7 @@ def parent_path(path: PathLike) -> pathlib.Path:
261261
return path.parent
262262

263263

264-
def read(filename: PathLike, **kwargs) -> str:
264+
def read(filename: PathLike, **kwargs) -> str: # noqa: PRM002
265265
"""
266266
Read a file in the current directory (in text mode).
267267
@@ -308,7 +308,7 @@ def relpath(path: PathLike, relative_to: Optional[PathLike] = None) -> pathlib.P
308308
return abs_path
309309

310310

311-
def write(var: str, filename: PathLike, **kwargs) -> None:
311+
def write(var: str, filename: PathLike, **kwargs) -> None: # noqa: PRM002
312312
"""
313313
Write a variable to file in the current directory.
314314
@@ -518,7 +518,7 @@ def write_lines(
518518
encoding: Optional[str] = "UTF-8",
519519
errors: Optional[str] = None,
520520
*,
521-
trailing_whitespace: bool = False
521+
trailing_whitespace: bool = False,
522522
) -> None:
523523
"""
524524
Write the given list of lines to the file without trailing whitespace.
@@ -536,7 +536,7 @@ def write_lines(
536536
if isinstance(data, str):
537537
warnings.warn(
538538
"Passing a string to PathPlus.write_lines writes each character to its own line.\n"
539-
"That probably isn't what you intended."
539+
"That probably isn't what you intended.",
540540
)
541541

542542
if trailing_whitespace:
@@ -592,7 +592,7 @@ def open( # type: ignore # noqa: A003 # pylint: disable=redefined-builtin
592592
encoding: Optional[str] = "UTF-8",
593593
errors: Optional[str] = None,
594594
newline: Optional[str] = NEWLINE_DEFAULT,
595-
) -> IO[Any]:
595+
) -> IO[Any]:
596596
"""
597597
Open the file pointed by this path and return a file object, as
598598
the built-in :func:`open` function does.
@@ -790,6 +790,8 @@ def unlink(self, missing_ok: bool = False) -> None:
790790
791791
If the path is a directory, use :meth:`~domdf_python_tools.paths.PathPlus.rmdir()` instead.
792792
793+
:param missing_ok:
794+
793795
.. versionadded:: 0.3.8 for Python 3.8 and above
794796
.. versionadded:: 0.11.0 for Python 3.6 and Python 3.7
795797
"""
@@ -1125,6 +1127,10 @@ class TemporaryPathPlus(tempfile.TemporaryDirectory):
11251127
11261128
Unlike :func:`tempfile.TemporaryDirectory` this class is based around a :class:`~.PathPlus` object.
11271129
1130+
:param suffix: A str suffix for the directory name.
1131+
:param prefix: A str prefix for the directory name.
1132+
:param dir: A directory to create this temp dir in.
1133+
11281134
.. versionadded:: 2.4.0
11291135
.. autosummary-widths:: 6/16
11301136
"""
@@ -1170,12 +1176,12 @@ def __enter__(self) -> PathPlus:
11701176

11711177

11721178
def sort_paths(*paths: PathLike) -> List[PathPlus]:
1173-
"""
1179+
r"""
11741180
Sort the ``paths`` by directory, then by file.
11751181
11761182
.. versionadded:: 2.6.0
11771183
1178-
:param paths:
1184+
:param \*paths:
11791185
"""
11801186

11811187
directories: Dict[str, List[PathPlus]] = defaultdict(list)
@@ -1259,7 +1265,7 @@ def phase4(self) -> None: # noqa: D102
12591265
"left_only": filecmp.dircmp.phase1,
12601266
"right_only": filecmp.dircmp.phase1,
12611267
"left_list": filecmp.dircmp.phase0,
1262-
"right_list": filecmp.dircmp.phase0
1268+
"right_list": filecmp.dircmp.phase0,
12631269
}
12641270

12651271
methodmap = _methodmap # type: ignore[assignment]

domdf_python_tools/pretty_print.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _pprint_dict(
150150
allowance + 1,
151151
context,
152152
level,
153-
)
153+
)
154154

155155
write(self._make_close('}', indent, obj))
156156

@@ -250,7 +250,7 @@ def _format_attribute_items(self, items, stream, indent, allowance, context, lev
250250
allowance if last else 1,
251251
context,
252252
level,
253-
)
253+
)
254254

255255
if not last:
256256
write(delimnl)
@@ -263,7 +263,7 @@ def simple_repr(*attributes: str, show_module: bool = False, **kwargs):
263263
r"""
264264
Adds a simple ``__repr__`` method to the decorated class.
265265
266-
:param attributes: The attributes to include in the ``__repr__``.
266+
:param \*attributes: The attributes to include in the ``__repr__``.
267267
:param show_module: Whether to show the name of the module in the ``__repr__``.
268268
:param \*\*kwargs: Keyword arguments passed on to :class:`pprint.PrettyPrinter`.
269269
"""

domdf_python_tools/stringlist.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __repr__(self) -> str:
108108

109109
return f"{type(self).__name__}(size={self.size}, type={self.type!r})"
110110

111-
def __eq__(self, other):
111+
def __eq__(self, other) -> bool: # noqa: MAN001
112112
if isinstance(other, Indent):
113113
return other.size == self.size and other.type == self.type
114114
elif isinstance(other, str):
@@ -252,7 +252,7 @@ def __setitem__(self, index: Union[SupportsIndex, slice], line: Union[String, It
252252
for lline, idx in zip(
253253
reversed(line),
254254
reversed(range(index.start or 0, index.stop + 1, index.step or 1)),
255-
):
255+
):
256256
self[idx] = lline
257257
else:
258258
line = cast(String, line)
@@ -304,7 +304,7 @@ def blankline(self, ensure_single: bool = False):
304304

305305
self.append('')
306306

307-
def set_indent_size(self, size: int = 0):
307+
def set_indent_size(self, size: int = 0) -> None:
308308
"""
309309
Sets the size of the indent to insert at the beginning of new lines.
310310
@@ -313,7 +313,7 @@ def set_indent_size(self, size: int = 0):
313313

314314
self.indent.size = int(size)
315315

316-
def set_indent_type(self, indent_type: str = '\t'):
316+
def set_indent_type(self, indent_type: str = '\t') -> None:
317317
"""
318318
Sets the type of the indent to insert at the beginning of new lines.
319319
@@ -322,7 +322,7 @@ def set_indent_type(self, indent_type: str = '\t'):
322322

323323
self.indent.type = str(indent_type)
324324

325-
def set_indent(self, indent: Union[String, Indent], size: int = 0):
325+
def set_indent(self, indent: Union[String, Indent], size: int = 0) -> None:
326326
"""
327327
Sets the indent to insert at the beginning of new lines.
328328
@@ -386,7 +386,7 @@ def __bytes__(self) -> bytes:
386386

387387
return str(self).encode("UTF-8")
388388

389-
def __eq__(self, other) -> bool:
389+
def __eq__(self, other) -> bool: # noqa: PRM002
390390
"""
391391
Returns whether the other object is equal to this :class:`~domdf_python_tools.stringlist.StringList`.
392392
"""
@@ -467,6 +467,8 @@ def splitlines(self, keepends: bool = False) -> List[str]:
467467
"""
468468
Analagous to :meth:`str.splitlines`.
469469
470+
:param keepends:
471+
470472
.. versionadded:: 3.8.0
471473
"""
472474

domdf_python_tools/terminal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def __enter__(self):
179179

180180
self.locals_on_entry = self.parent_frame.f_locals.copy() # type: ignore[union-attr]
181181

182-
def __exit__(self, *args, **kwargs):
182+
def __exit__(self, *args, **kwargs): # noqa: PRM002
183183
"""
184184
Called when exiting the context manager.
185185
"""

0 commit comments

Comments
 (0)