Skip to content

Commit 91b02db

Browse files
committed
Lint
1 parent 65ae56b commit 91b02db

File tree

11 files changed

+99
-84
lines changed

11 files changed

+99
-84
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
def foo():
1+
def foo(): # noqa
22
pass
33

44

5-
def bar():
5+
def bar(): # noqa
66
pass

tests/list_tests.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ def test_extend(self):
296296
# overflow test. issue1621
297297
class CustomIter:
298298

299-
def __iter__(self):
299+
def __iter__(self): # noqa: MAN002
300300
return self
301301

302-
def __next__(self):
302+
def __next__(self): # noqa: MAN002
303303
raise StopIteration
304304

305-
def __length_hint__(self):
305+
def __length_hint__(self): # noqa: MAN002
306306
return sys.maxsize
307307

308308
a = self.type2test([1, 2, 3, 4])
@@ -378,7 +378,7 @@ class BadExc(Exception):
378378

379379
class BadCmp:
380380

381-
def __eq__(self, other):
381+
def __eq__(self, other): # noqa: MAN001,MAN002
382382
if other == 2:
383383
raise BadExc()
384384
return False
@@ -389,7 +389,7 @@ def __eq__(self, other):
389389

390390
class BadCmp2:
391391

392-
def __eq__(self, other):
392+
def __eq__(self, other): # noqa: MAN001,MAN002
393393
raise BadExc()
394394

395395
d = self.type2test("abcdefghcij")
@@ -422,10 +422,10 @@ def test_index(self):
422422
# Test modifying the list during index's iteration
423423
class EvilCmp:
424424

425-
def __init__(self, victim):
425+
def __init__(self, victim): # noqa: MAN001
426426
self.victim = victim
427427

428-
def __eq__(self, other):
428+
def __eq__(self, other): # noqa: MAN001,MAN002
429429
del self.victim[:]
430430
return False
431431

@@ -501,7 +501,7 @@ def test_sort(self):
501501
with pytest.raises(TypeError):
502502
u.sort(42, 42)
503503

504-
def revcmp(a, b):
504+
def revcmp(a, b): # noqa: MAN001,MAN002
505505
if a == b:
506506
return 0
507507
elif a < b:
@@ -602,7 +602,7 @@ def test_constructor_exception_handling(self):
602602
# Bug #1242657
603603
class F:
604604

605-
def __iter__(self):
605+
def __iter__(self): # noqa: MAN002
606606
raise KeyboardInterrupt
607607

608608
with pytest.raises(KeyboardInterrupt):

tests/test_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_creation(self, alice):
6464
assert alice.age == 20
6565
assert alice.occupation == "IRC Lurker"
6666

67-
def test_str(self, alice):
67+
def test_str(self, alice: object):
6868
assert str(alice).startswith("<tests.test_bases.Person")
6969

7070
def test_equality(self):

tests/test_dir_comparator.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import shutil
1313
from contextlib import redirect_stdout
1414
from io import StringIO
15-
from types import SimpleNamespace
1615

1716
# 3rd party
1817
import pytest
@@ -21,9 +20,18 @@
2120
from domdf_python_tools.paths import DirComparator, PathPlus, compare_dirs
2221

2322

23+
class ComparatorTmpdirData:
24+
__slots__ = ("dir", "dir_same", "dir_diff", "dir_ignored", "caseinsensitive")
25+
dir: str # noqa: A003 # pylint: disable=redefined-builtin
26+
dir_same: str
27+
dir_diff: str
28+
dir_ignored: str
29+
caseinsensitive: bool
30+
31+
2432
@pytest.fixture()
25-
def comparator_tmpdir(tmp_pathplus):
26-
data = SimpleNamespace()
33+
def comparator_tmpdir(tmp_pathplus: PathPlus) -> ComparatorTmpdirData:
34+
data = ComparatorTmpdirData()
2735
data.dir = os.path.join(tmp_pathplus, "dir")
2836
data.dir_same = os.path.join(tmp_pathplus, "dir-same")
2937
data.dir_diff = os.path.join(tmp_pathplus, "dir-diff")

tests/test_getters.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# stdlib
1010
import pickle
11+
from typing import Any
1112

1213
# 3rd party
1314
import pytest
@@ -276,10 +277,10 @@ class A:
276277
def foo(self, *args, **kwds):
277278
return args[0] + args[1]
278279

279-
def bar(self, f=42):
280+
def bar(self, f=42): # noqa: MAN001,MAN002
280281
return f
281282

282-
def baz(*args, **kwds):
283+
def baz(*args, **kwds): # noqa: MAN002
283284
return kwds["name"], kwds["self"]
284285

285286
a = A()
@@ -370,6 +371,6 @@ def test_repr(self):
370371
evaluate(repr(methodcaller(1, "__iter__", "arg1", "arg2", kw1="kwarg1", kw2="kwarg2")))
371372

372373

373-
def copy(obj, proto):
374+
def copy(obj: Any, proto: int):
374375
pickled = pickle.dumps(obj, proto)
375376
return pickle.loads(pickled) # nosec: B301

tests/test_iterative.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from itertools import islice
2222
from random import shuffle
2323
from types import GeneratorType
24-
from typing import List, Tuple
24+
from typing import Any, Iterable, List, Optional, Sequence, Tuple, TypeVar
2525

2626
# 3rd party
2727
import pytest
@@ -241,7 +241,7 @@ def test_ranges_from_iterable():
241241
assert list(ranges_from_iterable([1, 2, 3, 4, 5, 7, 8, 9, 10])) == expects
242242

243243

244-
def _extend_param(sequence, expects):
244+
def _extend_param(sequence: Sequence, expects: Any):
245245
return pytest.param(sequence, expects, id=sequence)
246246

247247

@@ -257,7 +257,7 @@ def _extend_param(sequence, expects):
257257
pytest.param(['a', 'b', 'c', 'd', 'e'], "abcde", id="list"),
258258
]
259259
)
260-
def test_extend(sequence, expects):
260+
def test_extend(sequence: Sequence[str], expects: str):
261261
assert ''.join(extend(sequence, 4)) == expects
262262

263263

@@ -273,7 +273,7 @@ def test_extend(sequence, expects):
273273
pytest.param(['a', 'b', 'c', 'd', 'e'], "abcde", id="list"),
274274
]
275275
)
276-
def test_extend_with(sequence, expects):
276+
def test_extend_with(sequence: Sequence[str], expects: str):
277277
assert ''.join(extend_with(sequence, 4, 'z')) == expects
278278

279279

@@ -294,7 +294,10 @@ def lzip(*args):
294294
return list(zip(*args))
295295

296296

297-
def take(n, seq):
297+
_T = TypeVar("_T")
298+
299+
300+
def take(n: Optional[int], seq: Iterable[_T]) -> List[_T]:
298301
"""
299302
Convenience function for partially consuming a long of infinite iterable
300303
"""
@@ -417,7 +420,7 @@ def test_count_with_stride():
417420
# pickletest(proto, count(i, j))
418421

419422

420-
def pickletest(protocol, it, stop=4, take=1, compare=None):
423+
def pickletest(protocol: int, it, stop: int = 4, take: int = 1, compare=None):
421424
"""
422425
Test that an iterator is the same after pickling, also when part-consumed
423426
"""

tests/test_pagesizes/test_pagesizes.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# stdlib
1010
from math import isclose
11+
from typing import List, Tuple, Type
1112

1213
# 3rd party
1314
import pytest
@@ -28,6 +29,7 @@
2829
Size_mm,
2930
Size_pica,
3031
Size_um,
32+
Unit,
3133
cm,
3234
convert_from,
3335
inch,
@@ -65,7 +67,7 @@
6567
),
6668
],
6769
)
68-
def test_repr(obj, expects):
70+
def test_repr(obj: Unit, expects: str):
6971
assert repr(obj) == expects
7072

7173

@@ -78,12 +80,12 @@ def test_repr(obj, expects):
7880
(Size_pica(12, 34), "Size_pica(width=12, height=34)"),
7981
],
8082
)
81-
def test_str(obj, expects):
83+
def test_str(obj: Unit, expects: str):
8284
assert str(obj) == expects
8385

8486

8587
@pytest.mark.parametrize("size", [A6, A5, A4, A3, A2, A1, A0])
86-
def test_orientation(size):
88+
def test_orientation(size: BaseSize):
8789
assert size.is_portrait()
8890
assert size.portrait().is_portrait()
8991
assert size.landscape().portrait().is_portrait()
@@ -106,7 +108,7 @@ def test_is_square():
106108

107109

108110
@pytest.mark.parametrize("unit", [pt, inch, cm, mm, um, pc])
109-
def test_convert_size(unit):
111+
def test_convert_size(unit: Unit):
110112
size = PageSize(12, 34, unit)
111113
unit_str = unit.name
112114
if unit_str == "µm":
@@ -176,7 +178,7 @@ def test_convert_size(unit):
176178
pytest.param(2, 5, 10, id="not isinstance(from_, Unit)"),
177179
],
178180
)
179-
def test_convert_from(value, unit, expects):
181+
def test_convert_from(value: List[int], unit, expects: Tuple[float, ...]):
180182
assert convert_from(value, unit) == expects
181183

182184

@@ -187,7 +189,7 @@ def test_convert_from(value, unit, expects):
187189
((12, 34), Size_mm(12, 34), Size_mm),
188190
],
189191
)
190-
def test_from_size(size, expected, class_):
192+
def test_from_size(size: Tuple[int, int], expected: Unit, class_: Type[BaseSize]):
191193
print(class_.from_size(size))
192194
assert class_.from_size(size) == expected
193195

@@ -210,7 +212,7 @@ def test_from_size(size, expected, class_):
210212
("10μm", [("10", "μm")]),
211213
],
212214
)
213-
def test_measurement_re(string, expects):
215+
def test_measurement_re(string: str, expects: Unit):
214216
assert _measurement_re.findall(string) == expects
215217

216218

@@ -261,5 +263,5 @@ def test_parse_measurement_errors():
261263
("5in", 5 * inch),
262264
],
263265
)
264-
def test_parse_measurement(string, expects):
266+
def test_parse_measurement(string: str, expects: Unit):
265267
assert parse_measurement(string) == expects

0 commit comments

Comments
 (0)