Skip to content

Commit 6c9a924

Browse files
authored
Merge pull request #46 from mhchia/feature/add-flake8
Add flake8 to tox and CI
2 parents 1c9403d + a17b8fe commit 6c9a924

File tree

13 files changed

+54
-34
lines changed

13 files changed

+54
-34
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[flake8]
2-
exclude = multiaddr/protocols.csv
2+
max-line-length = 100

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ sudo: false
22
language: python
33
matrix:
44
include:
5+
- python: 3.6
6+
env: TOXENV=lint
57
- python: 2.7
68
env: TOXENV=py27
79
- python: 3.4

multiaddr/codecs/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class NoneCodec:
1313

1414

1515
CODEC_CACHE = {}
16+
17+
1618
def codec_by_name(name):
1719
if name is None: # Special “do nothing – expect nothing” pseudo-codec
1820
return NoneCodec

multiaddr/codecs/p2p.py

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

1313
def to_bytes(proto, string):
1414
# the address is a base58-encoded string
15-
if six.PY2 and isinstance(string, unicode): # pragma: no cover (PY2)
15+
if six.PY2 and isinstance(string, unicode): # pragma: no cover (PY2) # noqa: F821
1616
string = string.encode("ascii")
1717
mm = base58.b58decode(string)
1818
if len(mm) < 5:

multiaddr/exceptions.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class ProtocolLookupError(LookupError):
1010
"""
1111
MultiAddr did not contain a protocol with the requested code
1212
"""
13-
13+
1414
def __init__(self, proto, string):
15-
self.proto = proto
15+
self.proto = proto
1616
self.string = string
17-
17+
1818
super(ProtocolLookupError, self).__init__(
1919
"MultiAddr {0!r} does not contain protocol {1}".format(string, proto)
2020
)
@@ -30,8 +30,8 @@ class StringParseError(ParseError):
3030
"""
3131

3232
def __init__(self, message, string, protocol=None, original=None):
33-
self.message = message
34-
self.string = string
33+
self.message = message
34+
self.string = string
3535
self.protocol = protocol
3636
self.original = original
3737

@@ -49,8 +49,8 @@ class BinaryParseError(ParseError):
4949
"""
5050

5151
def __init__(self, message, binary, protocol, original=None):
52-
self.message = message
53-
self.binary = binary
52+
self.message = message
53+
self.binary = binary
5454
self.protocol = protocol
5555
self.original = original
5656

@@ -69,19 +69,20 @@ class ProtocolExistsError(ProtocolManagerError):
6969
"""
7070
def __init__(self, proto, kind="name"):
7171
self.proto = proto
72-
self.kind = kind
72+
self.kind = kind
7373

7474
super(ProtocolExistsError, self).__init__(
7575
"Protocol with {0} {1!r} already exists".format(kind, getattr(proto, kind))
7676
)
7777

78+
7879
class ProtocolNotFoundError(ProtocolManagerError):
7980
"""
8081
No protocol with the given name or code found
8182
"""
8283
def __init__(self, value, kind="name"):
8384
self.value = value
84-
self.kind = kind
85+
self.kind = kind
8586

8687
super(ProtocolNotFoundError, self).__init__(
8788
"No protocol with {0} {1!r} found".format(kind, value)

multiaddr/multiaddr.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
22
try:
3-
import collections.abc
3+
import collections.abc
44
except ImportError: # pragma: no cover (PY2)
5-
import collections
6-
collections.abc = collections
5+
import collections
6+
collections.abc = collections
77

88
import six
99

@@ -17,7 +17,6 @@
1717
__all__ = ("Multiaddr",)
1818

1919

20-
2120
class MultiAddrKeys(collections.abc.KeysView, collections.abc.Sequence):
2221
def __contains__(self, proto):
2322
proto = protocols.protocol_with_any(proto)
@@ -59,7 +58,15 @@ def __iter__(self):
5958
# If we have an address, return it
6059
yield proto, codec.to_string(proto, part)
6160
except Exception as exc:
62-
six.raise_from(exceptions.BinaryParseError(str(exc), self._mapping.to_bytes(), proto.name, exc), exc)
61+
six.raise_from(
62+
exceptions.BinaryParseError(
63+
str(exc),
64+
self._mapping.to_bytes(),
65+
proto.name,
66+
exc,
67+
),
68+
exc,
69+
)
6370
else:
6471
# We were given something like '/utp', which doesn't have
6572
# an address, so return None
@@ -82,7 +89,6 @@ def __iter__(self):
8289
yield value
8390

8491

85-
8692
class Multiaddr(collections.abc.Mapping):
8793
"""Multiaddr is a representation of multiple nested internet addresses.
8894
@@ -200,13 +206,13 @@ def decapsulate(self, other):
200206

201207
def value_for_protocol(self, proto):
202208
"""Return the value (if any) following the specified protocol
203-
209+
204210
Returns
205211
-------
206212
union[object, NoneType]
207213
The parsed protocol value for the given protocol code or ``None``
208214
if the given protocol does not require any value
209-
215+
210216
Raises
211217
------
212218
~multiaddr.exceptions.BinaryParseError

multiaddr/protocols.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
]
6868

6969

70-
7170
class Protocol(object):
7271
__slots__ = [
7372
"code", # int
@@ -80,7 +79,7 @@ def __init__(self, code, name, codec):
8079
raise TypeError("code must be an integer")
8180
if not isinstance(name, six.string_types):
8281
raise TypeError("name must be a string")
83-
if not isinstance(codec, six.string_types) and not codec is None:
82+
if not isinstance(codec, six.string_types) and codec is not None:
8483
raise TypeError("codec must be a string or None")
8584

8685
self.code = code

multiaddr/transforms.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from .protocols import read_varint_code
1313

1414

15-
1615
def string_to_bytes(string):
1716
bs = []
1817
for proto, codec, value in string_iter(string):
@@ -90,7 +89,14 @@ def bytes_iter(buf):
9089
proto = protocol_with_code(code)
9190
codec = codec_by_name(proto.codec)
9291
except (ImportError, exceptions.ProtocolNotFoundError) as exc:
93-
six.raise_from(exceptions.BinaryParseError("Unknown Protocol", buf, proto.name if proto else code), exc)
92+
six.raise_from(
93+
exceptions.BinaryParseError(
94+
"Unknown Protocol",
95+
buf,
96+
proto.name if proto else code,
97+
),
98+
exc,
99+
)
94100
size, num_bytes_read2 = size_for_addr(codec, buf[num_bytes_read:])
95101
length = size + num_bytes_read2 + num_bytes_read
96102
yield proto, codec, buf[(length - size):length]

requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
bumpversion==0.5.3
44
wheel==0.29.0
55
watchdog==0.8.3
6-
flake8==2.5.4
76
tox==3.6.1
87
coverage==4.5.2
98
Sphinx==1.3.6
9+
flake8==3.7.7
1010
pytest
1111
pytest-cov

tests/test_multiaddr.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def test_views():
239239
"/ip4/127.0.0.1/utp/tcp/5555/udp/1234/utp/"
240240
"p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP")
241241

242-
for idx, (proto1, proto2, item, value) in enumerate(zip(ma, ma.keys(), ma.items(), ma.values())):
242+
for idx, (proto1, proto2, item, value) in enumerate(zip(ma, ma.keys(), ma.items(), ma.values())): # noqa: E501
243243
assert (proto1, value) == (proto2, value) == item
244244
assert proto1 in ma
245245
assert proto2 in ma.keys()
@@ -253,7 +253,7 @@ def test_views():
253253
assert len(list(ma.keys())) == len(ma.keys())
254254
assert len(list(ma.items())) == len(ma.items())
255255
assert len(list(ma.values())) == len(ma.values())
256-
256+
257257
with pytest.raises(IndexError):
258258
ma.keys()[len(ma)]
259259
with pytest.raises(IndexError):
@@ -282,9 +282,6 @@ def test_value_for_protocol_argument_wrong_type():
282282
with pytest.raises(ProtocolNotFoundError):
283283
a.value_for_protocol('str123')
284284

285-
286-
def test_value_for_protocol_argument_wrong_type():
287-
a = Multiaddr("/ip4/127.0.0.1/udp/1234")
288285
with pytest.raises(TypeError):
289286
a.value_for_protocol(None)
290287

0 commit comments

Comments
 (0)