Skip to content

Commit 5074699

Browse files
author
Ivan Levkivskyi
committed
Fix lint (that was not run for looong time)
1 parent 096abda commit 5074699

10 files changed

+113
-104
lines changed

.flake8-tests

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[flake8]
99
# fake builtins for python2/*
1010
builtins = basestring, unicode
11-
max-line-length = 90
11+
max-line-length = 100
1212
ignore =
1313
# temporary ignores until we sort it out
1414
E306,
@@ -18,6 +18,8 @@ ignore =
1818
# irrelevant plugins
1919
B3,
2020
DW12
21+
# consistency with mypy
22+
W504
2123
exclude =
2224
# This config is NOT for the main module.
2325
setup.py

python2/test_typing.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,6 @@ def __new__(cls, arg):
18271827
self.assertEqual(c.from_c, 'c')
18281828

18291829

1830-
18311830
class ClassVarTests(BaseTestCase):
18321831

18331832
def test_basics(self):
@@ -2308,8 +2307,8 @@ def __len__(self):
23082307
self.assertIsSubclass(MMB[str, str], typing.Mapping)
23092308
self.assertIsSubclass(MMC, MMA)
23102309

2311-
class I(typing.Iterable): pass
2312-
self.assertNotIsSubclass(list, I)
2310+
class It(typing.Iterable): pass
2311+
self.assertNotIsSubclass(list, It)
23132312

23142313
class G(typing.Generator[int, int, int]): pass
23152314
def g(): yield 0
@@ -2366,8 +2365,8 @@ class S(collections.MutableSequence): pass
23662365
self.assertIsSubclass(S, typing.MutableSequence)
23672366
self.assertIsSubclass(S, typing.Iterable)
23682367

2369-
class I(collections.Iterable): pass
2370-
self.assertIsSubclass(I, typing.Iterable)
2368+
class It(collections.Iterable): pass
2369+
self.assertIsSubclass(It, typing.Iterable)
23712370

23722371
class A(collections.Mapping): pass
23732372
class B: pass
@@ -2659,7 +2658,7 @@ def test_respect_no_type_check(self):
26592658
class NoTpCheck(object):
26602659
class Inn(object):
26612660
def __init__(self, x):
2662-
# type: (this is not actually a type) -> None
2661+
# type: (this is not actually a type) -> None # noqa
26632662
pass
26642663
self.assertTrue(NoTpCheck.__no_type_check__)
26652664
self.assertTrue(NoTpCheck.Inn.__init__.__no_type_check__)

python2/typing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,8 @@ def __init__(cls, *args, **kwargs):
17801780
if cls._is_protocol:
17811781
for base in cls.__mro__[1:]:
17821782
if not (base in (object, Generic) or
1783-
base.__module__ == '_abcoll' and base.__name__ in _PROTO_WHITELIST or
1783+
base.__module__ == '_abcoll' and
1784+
base.__name__ in _PROTO_WHITELIST or
17841785
isinstance(base, TypingMeta) and base._is_protocol or
17851786
isinstance(base, GenericMeta) and base.__origin__ is Generic):
17861787
raise TypeError('Protocols can only inherit from other protocols,'

src/mod_generics_cache.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
1313
T = TypeVar('T')
1414
15-
1615
class A(Generic[T]):
1716
some_b: 'B'
1817
19-
2018
class B(Generic[T]):
2119
class A(Generic[T]):
2220
pass
@@ -35,13 +33,11 @@ class A(Generic[T]):
3533

3634
T = TypeVar('T')
3735

38-
3936
class A(Generic[T]):
4037
__annotations__ = dict(
4138
some_b='B'
4239
)
4340

44-
4541
class B(Generic[T]):
4642
class A(Generic[T]):
4743
pass

src/test_typing.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from typing import TypeVar, AnyStr
1313
from typing import T, KT, VT # Not in __all__.
1414
from typing import Union, Optional
15-
from typing import Tuple, List, MutableMapping
15+
from typing import Tuple, List, MutableMapping, Iterator
1616
from typing import Callable
1717
from typing import Generic, ClassVar, GenericMeta
1818
from typing import cast
@@ -1539,7 +1539,7 @@ def test_syntax_error(self):
15391539

15401540
def test_delayed_syntax_error(self):
15411541

1542-
def foo(a: 'Node[T'):
1542+
def foo(a: 'Node[T'): # noqa
15431543
pass
15441544

15451545
with self.assertRaises(SyntaxError):
@@ -1555,7 +1555,7 @@ def foo(a: Tuple['42']):
15551555

15561556
def test_name_error(self):
15571557

1558-
def foo(a: 'Noode[T]'):
1558+
def foo(a: 'Noode[T]'): # noqa
15591559
pass
15601560

15611561
with self.assertRaises(NameError):
@@ -1564,7 +1564,7 @@ def foo(a: 'Noode[T]'):
15641564
def test_no_type_check(self):
15651565

15661566
@no_type_check
1567-
def foo(a: 'whatevers') -> {}:
1567+
def foo(a: 'int') -> {}:
15681568
pass
15691569

15701570
th = get_type_hints(foo)
@@ -1574,7 +1574,7 @@ def test_no_type_check_class(self):
15741574

15751575
@no_type_check
15761576
class C:
1577-
def foo(a: 'whatevers') -> {}:
1577+
def foo(a: 'int') -> {}:
15781578
pass
15791579

15801580
cth = get_type_hints(C.foo)
@@ -1600,12 +1600,12 @@ def magic_decorator(deco):
16001600
self.assertEqual(magic_decorator.__name__, 'magic_decorator')
16011601

16021602
@magic_decorator
1603-
def foo(a: 'whatevers') -> {}:
1603+
def foo(a: 'int') -> {}:
16041604
pass
16051605

16061606
@magic_decorator
16071607
class C:
1608-
def foo(a: 'whatevers') -> {}:
1608+
def foo(a: 'int') -> {}:
16091609
pass
16101610

16111611
self.assertEqual(foo.__name__, 'foo')
@@ -1764,7 +1764,7 @@ async def g_with(am: AsyncContextManager[int]):
17641764
# fake names for the sake of static analysis
17651765
ann_module = ann_module2 = ann_module3 = None
17661766
A = B = CSub = G = CoolEmployee = CoolEmployeeWithDefault = object
1767-
XMeth = XRepr = NoneAndForward = object
1767+
XMeth = XRepr = NoneAndForward = HasForeignBaseClass = object
17681768

17691769
gth = get_type_hints
17701770

@@ -1826,7 +1826,7 @@ def test_respect_no_type_check(self):
18261826
@no_type_check
18271827
class NoTpCheck:
18281828
class Inn:
1829-
def __init__(self, x: 'not a type'): ...
1829+
def __init__(self, x: 'not a type'): ... # noqa
18301830
self.assertTrue(NoTpCheck.__no_type_check__)
18311831
self.assertTrue(NoTpCheck.Inn.__init__.__no_type_check__)
18321832
self.assertEqual(gth(ann_module2.NTC.meth), {})
@@ -2233,8 +2233,8 @@ def __len__(self):
22332233
self.assertIsSubclass(MMB[str, str], typing.Mapping)
22342234
self.assertIsSubclass(MMC, MMA)
22352235

2236-
class I(typing.Iterable): ...
2237-
self.assertNotIsSubclass(list, I)
2236+
class It(typing.Iterable): ...
2237+
self.assertNotIsSubclass(list, It)
22382238

22392239
class G(typing.Generator[int, int, int]): ...
22402240
def g(): yield 0
@@ -2316,8 +2316,8 @@ class S(collections_abc.MutableSequence): ...
23162316
self.assertIsSubclass(S, typing.MutableSequence)
23172317
self.assertIsSubclass(S, typing.Iterable)
23182318

2319-
class I(collections_abc.Iterable): ...
2320-
self.assertIsSubclass(I, typing.Iterable)
2319+
class It(collections_abc.Iterable): ...
2320+
self.assertIsSubclass(It, typing.Iterable)
23212321

23222322
class A(collections_abc.Mapping, metaclass=abc.ABCMeta): ...
23232323
class B: ...

tox.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ ignore =
1717
B3,
1818
DW12,
1919
# code is sometimes better without this
20-
E129
20+
E129,
21+
# consistency with mypy
22+
W504
2123
exclude =
2224
# tests have more relaxed formatting rules
2325
# and its own specific config in .flake8-tests

typing_extensions/src_py2/test_typing_extensions.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import subprocess
66
from unittest import TestCase, main
77

8-
from typing_extensions import Annotated, NoReturn, ClassVar, Final, IntVar, Literal, TypedDict
8+
from typing_extensions import Annotated, NoReturn, ClassVar, IntVar
99
from typing_extensions import ContextManager, Counter, Deque, DefaultDict
1010
from typing_extensions import NewType, overload
1111
from typing import Dict, List
@@ -118,15 +118,15 @@ def test_no_isinstance(self):
118118

119119
class IntVarTests(BaseTestCase):
120120
def test_valid(self):
121-
T_ints = IntVar("T_ints")
121+
T_ints = IntVar("T_ints") # noqa
122122

123123
def test_invalid(self):
124124
with self.assertRaises(TypeError):
125125
T_ints = IntVar("T_ints", int)
126126
with self.assertRaises(TypeError):
127127
T_ints = IntVar("T_ints", bound=int)
128128
with self.assertRaises(TypeError):
129-
T_ints = IntVar("T_ints", covariant=True)
129+
T_ints = IntVar("T_ints", covariant=True) # noqa
130130

131131

132132
class CollectionsAbcTests(BaseTestCase):
@@ -332,8 +332,8 @@ def test_hash_eq(self):
332332

333333
def test_cannot_subclass(self):
334334
with self.assertRaises(TypeError):
335-
class C(Annotated):
336-
pass
335+
class C(Annotated):
336+
pass
337337

338338
def test_cannot_check_instance(self):
339339
with self.assertRaises(TypeError):
@@ -364,9 +364,9 @@ def test_subst(self):
364364
with self.assertRaises(TypeError):
365365
D[int]
366366

367-
I = Annotated[int, dec]
367+
It = Annotated[int, dec]
368368
with self.assertRaises(TypeError):
369-
I[None]
369+
It[None]
370370

371371
LI = L[int]
372372
with self.assertRaises(TypeError):
@@ -376,6 +376,7 @@ def test_annotated_in_other_types(self):
376376
X = List[Annotated[T, 5]]
377377
self.assertEqual(X[int], List[Annotated[int, 5]])
378378

379+
379380
class AllTests(BaseTestCase):
380381

381382
def test_typing_extensions_includes_standard(self):

typing_extensions/src_py2/typing_extensions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import abc
2-
import sys
32
import typing
4-
from typing import (
3+
from typing import ( # noqa
4+
# These are imported for re-export.
55
ClassVar, Type, Generic, Callable, GenericMeta, TypingMeta,
66
Counter, DefaultDict, Deque, TypeVar, Tuple, Final, final,
77
NewType, overload, Text, TYPE_CHECKING, Literal, TypedDict, Protocol,

typing_extensions/src_py3/test_typing_extensions.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from unittest import TestCase, main, skipUnless
1010
from typing import TypeVar, Optional
1111
from typing import T, KT, VT # Not in __all__.
12-
from typing import Tuple, List, Dict
12+
from typing import Tuple, List, Dict, Iterator
1313
from typing import Generic
1414
from typing import no_type_check
1515
from typing_extensions import NoReturn, ClassVar, Final, IntVar, Literal, Type, NewType, TypedDict
@@ -34,13 +34,13 @@
3434

3535
OLD_GENERICS = False
3636
try:
37-
from typing import _type_vars, _next_in_mro, _type_check
37+
from typing import _type_vars, _next_in_mro, _type_check # noqa
3838
except ImportError:
3939
OLD_GENERICS = True
4040

4141
# We assume Python versions *below* 3.5.0 will have the most
4242
# up-to-date version of the typing module installed. Since
43-
# the typing module isn't a part of the standard library in older
43+
# the typing module isn't a part of the standard library in older
4444
# versions of Python, those users are likely to have a reasonably
4545
# modern version of `typing` installed from PyPi.
4646
TYPING_LATEST = sys.version_info[:3] < (3, 5, 0)
@@ -73,6 +73,7 @@
7373
# Protocols are hard to backport to the original version of typing 3.5.0
7474
HAVE_PROTOCOLS = sys.version_info[:3] != (3, 5, 0)
7575

76+
7677
class BaseTestCase(TestCase):
7778
def assertIsSubclass(self, cls, class_or_tuple, msg=None):
7879
if not issubclass(cls, class_or_tuple):
@@ -226,15 +227,15 @@ def test_no_isinstance(self):
226227

227228
class IntVarTests(BaseTestCase):
228229
def test_valid(self):
229-
T_ints = IntVar("T_ints")
230+
T_ints = IntVar("T_ints") # noqa
230231

231232
def test_invalid(self):
232233
with self.assertRaises(TypeError):
233234
T_ints = IntVar("T_ints", int)
234235
with self.assertRaises(TypeError):
235236
T_ints = IntVar("T_ints", bound=int)
236237
with self.assertRaises(TypeError):
237-
T_ints = IntVar("T_ints", covariant=True)
238+
T_ints = IntVar("T_ints", covariant=True) # noqa
238239

239240

240241
class LiteralTests(BaseTestCase):
@@ -475,7 +476,7 @@ def test_respect_no_type_check(self):
475476
@no_type_check
476477
class NoTpCheck:
477478
class Inn:
478-
def __init__(self, x: 'not a type'): ...
479+
def __init__(self, x: 'not a type'): ... # noqa
479480
self.assertTrue(NoTpCheck.__no_type_check__)
480481
self.assertTrue(NoTpCheck.Inn.__init__.__no_type_check__)
481482
self.assertEqual(gth(ann_module2.NTC.meth), {})
@@ -502,6 +503,7 @@ def test_final_forward_ref(self):
502503
self.assertNotEqual(gth(Loop, globals())['attr'], Final[int])
503504
self.assertNotEqual(gth(Loop, globals())['attr'], Final)
504505

506+
505507
class CollectionsAbcTests(BaseTestCase):
506508

507509
def test_isinstance_collections(self):
@@ -1609,8 +1611,8 @@ def test_hash_eq(self):
16091611

16101612
def test_cannot_subclass(self):
16111613
with self.assertRaisesRegex(TypeError, "Cannot subclass .*Annotated"):
1612-
class C(Annotated):
1613-
pass
1614+
class C(Annotated):
1615+
pass
16141616

16151617
def test_cannot_check_instance(self):
16161618
with self.assertRaises(TypeError):
@@ -1620,7 +1622,6 @@ def test_cannot_check_subclass(self):
16201622
with self.assertRaises(TypeError):
16211623
issubclass(int, Annotated[int, "positive"])
16221624

1623-
16241625
@skipUnless(PEP_560, "pickle support was added with PEP 560")
16251626
def test_pickle(self):
16261627
samples = [typing.Any, typing.Union[int, str],
@@ -1673,9 +1674,9 @@ def test_subst(self):
16731674
with self.assertRaises(TypeError):
16741675
D[int]
16751676

1676-
I = Annotated[int, dec]
1677+
It = Annotated[int, dec]
16771678
with self.assertRaises(TypeError):
1678-
I[None]
1679+
It[None]
16791680

16801681
LI = L[int]
16811682
with self.assertRaises(TypeError):
@@ -1747,7 +1748,6 @@ def __iand__(self, other: Const["MySet[T]"]) -> "MySet[T]":
17471748
)
17481749

17491750

1750-
17511751
class AllTests(BaseTestCase):
17521752

17531753
def test_typing_extensions_includes_standard(self):
@@ -1782,7 +1782,6 @@ def test_typing_extensions_includes_standard(self):
17821782
self.assertIn('Protocol', a)
17831783
self.assertIn('runtime', a)
17841784

1785-
17861785
def test_typing_extensions_defers_when_possible(self):
17871786
exclude = {'overload', 'Text', 'TYPE_CHECKING', 'Final', 'get_type_hints'}
17881787
for item in typing_extensions.__all__:
@@ -1804,4 +1803,4 @@ def test_typing_extensions_compiles_with_opt(self):
18041803

18051804

18061805
if __name__ == '__main__':
1807-
main()
1806+
main()

0 commit comments

Comments
 (0)