Skip to content

Commit 5ed8c89

Browse files
committed
[flake8] whitespace changes
E226 whitespace around operator E251 unexpected spaces around keyword / parameter equals E261 at least two spaces before inline comment E271 multiple spaces after keyword E302 expected 2 blank lines, found 1 E303 too many blank lines E305 expected 2 blank lines after class or function definition, found 1 E306 expected 1 blank line before a nested definition, found 0 Also: * Ignored flake8 for now in test_*, there are incompatible practices there. * Marked a few errors as temporarily ignored until we resolve them by pull requests. * Added flake8 to be executed on Travis CI under Python 3.6
1 parent 2f5d978 commit 5ed8c89

File tree

5 files changed

+55
-17
lines changed

5 files changed

+55
-17
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ python:
1010
- "3.2"
1111
- "2.7"
1212

13+
install:
14+
- pip install -r test-requirements.txt
15+
1316
script:
1417
- export PYTHONPATH=`python -c "import sys; print('python2' if sys.version.startswith('2') else 'src')"`; py.test $PYTHONPATH
18+
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then flake8; fi

python2/typing.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def _qualname(x):
8686
# Fall back to just name.
8787
return x.__name__
8888

89+
8990
def _trim_name(nm):
9091
if nm.startswith('_') and nm not in ('_TypeAlias',
9192
'_ForwardRef', '_TypingBase', '_FinalTypingBase'):
@@ -245,7 +246,6 @@ class _TypeAlias(_TypingBase):
245246

246247
__slots__ = ('name', 'type_var', 'impl_type', 'type_checker')
247248

248-
249249
def __init__(self, name, type_var, impl_type, type_checker):
250250
"""Initializer.
251251
@@ -419,6 +419,7 @@ def __eq__(self, other):
419419
return self.__type__ == other.__type__
420420
return self is other
421421

422+
422423
ClassVar = _ClassVar(_root=True)
423424

424425

@@ -919,7 +920,7 @@ def _next_in_mro(cls):
919920
# Look for the last occurrence of Generic or Generic[...].
920921
for i, c in enumerate(cls.__mro__[:-1]):
921922
if isinstance(c, GenericMeta) and _gorg(c) is Generic:
922-
next_in_mro = cls.__mro__[i+1]
923+
next_in_mro = cls.__mro__[i + 1]
923924
return next_in_mro
924925

925926

@@ -1329,7 +1330,7 @@ def __getitem__(self, parameters):
13291330
with hashable arguments to improve speed.
13301331
"""
13311332

1332-
if self.__origin__ is not None or not _geqv(self, Callable):
1333+
if self.__origin__ is not None or not _geqv(self, Callable):
13331334
return super(CallableMeta, self).__getitem__(parameters)
13341335
if not isinstance(parameters, tuple) or len(parameters) != 2:
13351336
raise TypeError("Callable must be used as "
@@ -1432,7 +1433,7 @@ def no_type_check(arg):
14321433
no_type_check(obj)
14331434
try:
14341435
arg.__no_type_check__ = True
1435-
except TypeError: # built-in classes
1436+
except TypeError: # built-in classes
14361437
pass
14371438
return arg
14381439

@@ -1696,6 +1697,7 @@ def __new__(cls, *args, **kwds):
16961697
"use list() instead")
16971698
return _generic_new(list, cls, *args, **kwds)
16981699

1700+
16991701
class Deque(collections.deque, MutableSequence[T]):
17001702
__slots__ = ()
17011703
__extra__ = collections.deque
@@ -1706,6 +1708,7 @@ def __new__(cls, *args, **kwds):
17061708
"use deque() instead")
17071709
return _generic_new(collections.deque, cls, *args, **kwds)
17081710

1711+
17091712
class Set(set, MutableSet[T]):
17101713
__slots__ = ()
17111714
__extra__ = set
@@ -1932,23 +1935,23 @@ def isatty(self):
19321935
pass
19331936

19341937
@abstractmethod
1935-
def read(self, n = -1):
1938+
def read(self, n=-1):
19361939
pass
19371940

19381941
@abstractmethod
19391942
def readable(self):
19401943
pass
19411944

19421945
@abstractmethod
1943-
def readline(self, limit = -1):
1946+
def readline(self, limit=-1):
19441947
pass
19451948

19461949
@abstractmethod
1947-
def readlines(self, hint = -1):
1950+
def readlines(self, hint=-1):
19481951
pass
19491952

19501953
@abstractmethod
1951-
def seek(self, offset, whence = 0):
1954+
def seek(self, offset, whence=0):
19521955
pass
19531956

19541957
@abstractmethod
@@ -1960,7 +1963,7 @@ def tell(self):
19601963
pass
19611964

19621965
@abstractmethod
1963-
def truncate(self, size = None):
1966+
def truncate(self, size=None):
19641967
pass
19651968

19661969
@abstractmethod
@@ -2036,6 +2039,7 @@ class io(object):
20362039
TextIO = TextIO
20372040
BinaryIO = BinaryIO
20382041

2042+
20392043
io.__name__ = __name__ + b'.io'
20402044
sys.modules[io.__name__] = io
20412045

@@ -2053,5 +2057,6 @@ class re(object):
20532057
Pattern = Pattern
20542058
Match = Match
20552059

2060+
20562061
re.__name__ = __name__ + b'.re'
20572062
sys.modules[re.__name__] = re

src/typing.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ def _tp_cache(func):
631631

632632
cached = functools.lru_cache()(func)
633633
_cleanups.append(cached.cache_clear)
634+
634635
@functools.wraps(func)
635636
def inner(*args, **kwds):
636637
try:
@@ -840,7 +841,7 @@ def _next_in_mro(cls):
840841
# Look for the last occurrence of Generic or Generic[...].
841842
for i, c in enumerate(cls.__mro__[:-1]):
842843
if isinstance(c, GenericMeta) and _gorg(c) is Generic:
843-
next_in_mro = cls.__mro__[i+1]
844+
next_in_mro = cls.__mro__[i + 1]
844845
return next_in_mro
845846

846847

@@ -1252,7 +1253,7 @@ def __getitem__(self, parameters):
12521253
with hashable arguments to improve speed.
12531254
"""
12541255

1255-
if self.__origin__ is not None or not _geqv(self, Callable):
1256+
if self.__origin__ is not None or not _geqv(self, Callable):
12561257
return super().__getitem__(parameters)
12571258
if not isinstance(parameters, tuple) or len(parameters) != 2:
12581259
raise TypeError("Callable must be used as "
@@ -1280,7 +1281,7 @@ def __getitem_inner__(self, parameters):
12801281
return super().__getitem__(parameters)
12811282

12821283

1283-
class Callable(extra=collections_abc.Callable, metaclass = CallableMeta):
1284+
class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
12841285
"""Callable type; Callable[[int], str] is a function of (int) -> str.
12851286
12861287
The subscription syntax must always be used with exactly two
@@ -1485,7 +1486,7 @@ def no_type_check(arg):
14851486
no_type_check(obj)
14861487
try:
14871488
arg.__no_type_check__ = True
1488-
except TypeError: # built-in classes
1489+
except TypeError: # built-in classes
14891490
pass
14901491
return arg
14911492

@@ -1771,6 +1772,7 @@ class Mapping(Sized, Iterable[KT], Container[KT], Generic[KT, VT_co],
17711772
class MutableMapping(Mapping[KT, VT], extra=collections_abc.MutableMapping):
17721773
__slots__ = ()
17731774

1775+
17741776
if hasattr(collections_abc, 'Reversible'):
17751777
if hasattr(collections_abc, 'Collection'):
17761778
class Sequence(Reversible[T_co], Collection[T_co],
@@ -1804,6 +1806,7 @@ def __new__(cls, *args, **kwds):
18041806
"use list() instead")
18051807
return _generic_new(list, cls, *args, **kwds)
18061808

1809+
18071810
class Deque(collections.deque, MutableSequence[T], extra=collections.deque):
18081811

18091812
__slots__ = ()
@@ -1814,6 +1817,7 @@ def __new__(cls, *args, **kwds):
18141817
"use deque() instead")
18151818
return _generic_new(collections.deque, cls, *args, **kwds)
18161819

1820+
18171821
class Set(set, MutableSet[T], extra=set):
18181822

18191823
__slots__ = ()
@@ -1871,6 +1875,7 @@ def __new__(cls, *args, **kwds):
18711875
"use dict() instead")
18721876
return _generic_new(dict, cls, *args, **kwds)
18731877

1878+
18741879
class DefaultDict(collections.defaultdict, MutableMapping[KT, VT],
18751880
extra=collections.defaultdict):
18761881

@@ -1882,6 +1887,7 @@ def __new__(cls, *args, **kwds):
18821887
"use collections.defaultdict() instead")
18831888
return _generic_new(collections.defaultdict, cls, *args, **kwds)
18841889

1890+
18851891
# Determine what base class to use for Generator.
18861892
if hasattr(collections_abc, 'Generator'):
18871893
# Sufficiently recent versions of 3.5 have a Generator ABC.
@@ -1901,6 +1907,7 @@ def __new__(cls, *args, **kwds):
19011907
"create a subclass instead")
19021908
return _generic_new(_G_base, cls, *args, **kwds)
19031909

1910+
19041911
if hasattr(collections_abc, 'AsyncGenerator'):
19051912
class AsyncGenerator(AsyncIterator[T_co], Generic[T_co, T_contra],
19061913
extra=collections_abc.AsyncGenerator):
@@ -1984,6 +1991,7 @@ def __new__(cls, typename, bases, ns):
19841991
nm_tpl._field_defaults = defaults_dict
19851992
return nm_tpl
19861993

1994+
19871995
class NamedTuple(metaclass=NamedTupleMeta):
19881996
"""Typed version of namedtuple.
19891997
@@ -2207,6 +2215,7 @@ class io:
22072215
TextIO = TextIO
22082216
BinaryIO = BinaryIO
22092217

2218+
22102219
io.__name__ = __name__ + '.io'
22112220
sys.modules[io.__name__] = io
22122221

@@ -2224,5 +2233,6 @@ class re:
22242233
Pattern = Pattern
22252234
Match = Match
22262235

2236+
22272237
re.__name__ = __name__ + '.re'
22282238
sys.modules[re.__name__] = re

test-requirements.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
flake8; python_version >= '3.6'
2+
flake8-bugbear; python_version >= '3.6'
3+
flake8-pyi; python_version >= '3.6'
4+
pytest>=2.8
5+
pytest-xdist>=1.13
6+
pytest-cov>=2.4.0

tox.ini

+17-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,21 @@ commands = python -m unittest discover
88
[testenv:py27]
99
changedir = python2
1010

11-
[pep8]
12-
ignore = E129,E226,E251
13-
1411
[flake8]
15-
ignore = DW12,E226,E251,F401,F811
12+
# fake builtins for python2/*
13+
builtins = basestring, unicode
14+
ignore =
15+
# temporary ignores until we sort it out
16+
B007,
17+
E128,
18+
E129,
19+
E501,
20+
E711,
21+
W503,
22+
# irrelevant plugins
23+
B3,
24+
DW12
25+
exclude =
26+
# tests have more relaxed formatting rules
27+
python2/test_typing.py,
28+
src/test_typing.py

0 commit comments

Comments
 (0)