Skip to content

Commit 0c06357

Browse files
committed
Run flake8 through CI
1 parent a096f0f commit 0c06357

5 files changed

Lines changed: 47 additions & 30 deletions

File tree

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ matrix:
2727
dist: trusty
2828
env:
2929
- DEPS="$LEGACY_DEPS"
30+
- python: 3.7
31+
env:
32+
- TOXENV=flake8
3033

3134
install:
3235
- pip install $DEPS

goto.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ def __init__(self):
1616
code = (lambda: x if x else y).__code__.co_code
1717
opcode, oparg = struct.unpack_from('BB', code, 2)
1818

19-
# Starting with Python 3.6, the bytecode format has been changed to use
19+
# Starting with Python 3.6, the bytecode format has changed, using
2020
# 16-bit words (8-bit opcode + 8-bit argument) for each instruction,
21-
# as opposed to previously 24-bit (8-bit opcode + 16-bit argument) for
22-
# instructions that expect an argument or just 8-bit for those that don't.
21+
# as opposed to previously 24 bit (8-bit opcode + 16-bit argument)
22+
# for instructions that expect an argument and otherwise 8 bit.
2323
# https://bugs.python.org/issue26647
2424
if dis.opname[opcode] == 'POP_JUMP_IF_FALSE':
2525
self.argument = struct.Struct('B')
2626
self.have_argument = 0
27-
# As of Python 3.6, jump targets are still addressed by their byte
28-
# unit. This, however, is matter to change, so that jump targets,
29-
# in the future, will refer to the code unit (address in bytes / 2).
27+
# As of Python 3.6, jump targets are still addressed by their
28+
# byte unit. This is matter to change, so that jump targets,
29+
# in the future might refer to code units (address in bytes / 2).
3030
# https://bugs.python.org/issue26647
3131
self.jump_unit = 8 // oparg
3232
else:
@@ -43,13 +43,11 @@ def argument_bits(self):
4343

4444

4545
def _make_code(code, codestring):
46-
args = [
47-
code.co_argcount, code.co_nlocals, code.co_stacksize,
48-
code.co_flags, codestring, code.co_consts,
49-
code.co_names, code.co_varnames, code.co_filename,
50-
code.co_name, code.co_firstlineno, code.co_lnotab,
51-
code.co_freevars, code.co_cellvars
52-
]
46+
args = [code.co_argcount, code.co_nlocals, code.co_stacksize,
47+
code.co_flags, codestring, code.co_consts,
48+
code.co_names, code.co_varnames, code.co_filename,
49+
code.co_name, code.co_firstlineno, code.co_lnotab,
50+
code.co_freevars, code.co_cellvars]
5351

5452
try:
5553
args.insert(1, code.co_kwonlyargcount) # PY3
@@ -155,8 +153,9 @@ def _find_labels_and_gotos(code):
155153
name = code.co_names[oparg1]
156154
if name == 'label':
157155
if oparg2 in labels:
158-
co_name = code.co_names[oparg2]
159-
raise SyntaxError('Ambiguous label {0!r}'.format(co_name))
156+
raise SyntaxError('Ambiguous label {0!r}'.format(
157+
code.co_names[oparg2]
158+
))
160159
labels[oparg2] = (offset1,
161160
offset4,
162161
tuple(block_stack))
@@ -196,7 +195,9 @@ def _patch_code(code):
196195
try:
197196
_, target, target_stack = labels[label]
198197
except KeyError:
199-
raise SyntaxError('Unknown label {0!r}'.format(code.co_names[label]))
198+
raise SyntaxError('Unknown label {0!r}'.format(
199+
code.co_names[label]
200+
))
200201

201202
target_depth = len(target_stack)
202203
if origin_stack[:target_depth] != target_stack:

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
name='goto-statement',
99
version='1.2',
1010
url='https://github.com/snoack/python-goto/',
11-
description='A function decorator, that rewrites the bytecode, to enable goto in Python',
11+
description='A function decorator that rewrites the bytecode, '
12+
'enabling goto in Python',
1213
long_description=long_description,
1314
long_description_content_type='text/markdown',
1415
py_modules=['goto'],

test_goto.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import pytest
32
from goto import with_goto
43

@@ -79,9 +78,10 @@ def func():
7978
for i in range(2):
8079
for j in range(2):
8180
# These are more than 256 bytes of bytecode
82-
x += x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x
83-
x += x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x
84-
x += x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x
81+
x += x + x + x + x + x + x + x + x + x + x + x + x + x + x + x
82+
x += x + x + x + x + x + x + x + x + x + x + x + x + x + x + x
83+
x += x + x + x + x + x + x + x + x + x + x + x + x + x + x + x
84+
x += x + x + x + x + x + x + x + x + x + x + x + x + x + x + x
8585

8686
goto .end
8787
label .end
@@ -107,11 +107,15 @@ def func():
107107
for i11 in range(2):
108108
# These are more than
109109
# 256 bytes of bytecode
110-
x += x+x+x+x+x+x+x+x+x+x+x
111-
x += x+x+x+x+x+x+x+x+x+x+x
112-
x += x+x+x+x+x+x+x+x+x+x+x
113-
x += x+x+x+x+x+x+x+x+x+x+x
114-
x += x+x+x+x+x+x+x+x+x+x+x
110+
x += x + x + x + x + x + x
111+
x += x + x + x + x + x + x
112+
x += x + x + x + x + x + x
113+
x += x + x + x + x + x + x
114+
x += x + x + x + x + x + x
115+
x += x + x + x + x + x + x
116+
x += x + x + x + x + x + x
117+
x += x + x + x + x + x + x
118+
x += x + x + x + x + x + x
115119

116120
goto .end
117121
label .end
@@ -137,21 +141,21 @@ def func():
137141
try:
138142
rv = None
139143
goto .end
140-
except:
144+
except Exception:
141145
rv = 'except'
142146
finally:
143147
rv = 'finally'
144148
label .end
145149
return rv
146150

147-
assert func() == None
151+
assert func() is None
148152

149153

150154
def test_jump_into_try_block():
151155
def func():
152156
try:
153157
label .block
154-
except:
158+
except Exception:
155159
pass
156160
goto .block
157161

tox.ini

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
[tox]
2-
envlist = py26,py27,py32,py33,py34,py35,py36,py37,pypy,pypy3
2+
envlist = py26,py27,py32,py33,py34,py35,py36,py37,pypy,pypy3,flake8
33
skip_missing_interpreters = true
44

55
[testenv]
66
deps = pytest
77
commands = py.test
88

9+
[flake8]
10+
ignore = F821
11+
12+
[testenv:flake8]
13+
skip_install = true
14+
deps = flake8
15+
commands = flake8
16+
917
[legacy]
1018
deps =
1119
py<1.5

0 commit comments

Comments
 (0)