Skip to content

Commit e09e727

Browse files
emmatypingJukkaL
authored andcommitted
Correct lint errors and silence W504 (#5830)
Flake8 3.6.0 is a bit more strict on some things, so this fixes the complaints and silences W504 (line break after operator) since that is very common in our code (and we seem to silence W503 too). For an example of what the failing flake8 output looks like, see https://travis-ci.org/python/mypy/jobs/445480219.
1 parent 70e30ba commit e09e727

12 files changed

+25
-24
lines changed

mypy/binder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ def push_frame(self) -> Frame:
110110
self.options_on_return.append([])
111111
return f
112112

113-
def _put(self, key: Key, type: Type, index: int=-1) -> None:
113+
def _put(self, key: Key, type: Type, index: int = -1) -> None:
114114
self.frames[index].types[key] = type
115115

116-
def _get(self, key: Key, index: int=-1) -> Optional[Type]:
116+
def _get(self, key: Key, index: int = -1) -> Optional[Type]:
117117
if index < 0:
118118
index += len(self.frames)
119119
for i in range(index, -1, -1):

mypy/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ def atomic_write(filename: str, line1: str, line2: str) -> bool:
865865
for line in lines:
866866
f.write(line)
867867
os.replace(tmp_filename, filename)
868-
except os.error as err:
868+
except os.error:
869869
return False
870870
return True
871871

mypy/dmypy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def do_start(args: argparse.Namespace) -> None:
151151
"""
152152
try:
153153
get_status()
154-
except BadStatus as err:
154+
except BadStatus:
155155
# Bad or missing status file or dead process; good to start.
156156
pass
157157
else:
@@ -435,7 +435,7 @@ def check_status(data: Dict[str, Any]) -> Tuple[int, str]:
435435
raise BadStatus("pid field is not an int")
436436
try:
437437
os.kill(pid, 0)
438-
except OSError as err:
438+
except OSError:
439439
raise BadStatus("Daemon has died")
440440
if 'sockname' not in data:
441441
raise BadStatus("Invalid status file (no sockname field)")
@@ -456,7 +456,7 @@ def read_status() -> Dict[str, object]:
456456
with open(STATUS_FILE) as f:
457457
try:
458458
data = json.load(f)
459-
except Exception as err:
459+
except Exception:
460460
raise BadStatus("Malformed status file (not JSON)")
461461
if not isinstance(data, dict):
462462
raise BadStatus("Invalid status file (not a dict)")
@@ -467,7 +467,7 @@ def is_running() -> bool:
467467
"""Check if the server is running cleanly"""
468468
try:
469469
get_status()
470-
except BadStatus as err:
470+
except BadStatus:
471471
return False
472472
return True
473473

mypy/dmypy_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def serve(self) -> None:
170170
sys.exit(0)
171171
try:
172172
data = receive(conn)
173-
except OSError as err:
173+
except OSError:
174174
conn.close() # Maybe the client hung up
175175
continue
176176
resp = {} # type: Dict[str, Any]
@@ -192,7 +192,7 @@ def serve(self) -> None:
192192
raise
193193
try:
194194
conn.sendall(json.dumps(resp).encode('utf8'))
195-
except OSError as err:
195+
except OSError:
196196
pass # Maybe the client hung up
197197
conn.close()
198198
if command == 'stop':

mypy/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ class TypeVarExpr(SymbolNode, Expression):
19171917
def __init__(self, name: str, fullname: str,
19181918
values: List['mypy.types.Type'],
19191919
upper_bound: 'mypy.types.Type',
1920-
variance: int=INVARIANT) -> None:
1920+
variance: int = INVARIANT) -> None:
19211921
super().__init__()
19221922
self._name = name
19231923
self._fullname = fullname

mypy/solve.py

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

1212

1313
def solve_constraints(vars: List[TypeVarId], constraints: List[Constraint],
14-
strict: bool =True) -> List[Optional[Type]]:
14+
strict: bool = True) -> List[Optional[Type]]:
1515
"""Solve type constraints.
1616
1717
Return the best type(s) for type variables; each type can be None if the value of the variable

mypy/stubgen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def add_import_from(self, module: str, names: List[Tuple[str, Optional[str]]]) -
348348
if alias:
349349
self.reverse_alias[alias] = name
350350

351-
def add_import(self, module: str, alias: Optional[str]=None) -> None:
351+
def add_import(self, module: str, alias: Optional[str] = None) -> None:
352352
name = module.split('.')[0]
353353
self.module_for[alias or name] = None
354354
self.direct_imports[name] = module
@@ -625,7 +625,7 @@ def process_namedtuple(self, lvalue: NameExpr, rvalue: CallExpr) -> None:
625625
self.add('%s = namedtuple(%s, %s)\n' % (lvalue.name, name, items))
626626
self._state = CLASS
627627

628-
def is_type_expression(self, expr: Expression, top_level: bool=True) -> bool:
628+
def is_type_expression(self, expr: Expression, top_level: bool = True) -> bool:
629629
"""Return True for things that look like type expressions
630630
631631
Used to know if assignments look like typealiases
@@ -994,7 +994,7 @@ def default_python2_interpreter() -> str:
994994
raise SystemExit("Can't find a Python 2 interpreter -- please use the -p option")
995995

996996

997-
def usage(exit_nonzero: bool=True) -> None:
997+
def usage(exit_nonzero: bool = True) -> None:
998998
usage = textwrap.dedent("""\
999999
usage: stubgen [--py2] [--no-import] [--doc-dir PATH]
10001000
[--search-path PATH] [-p PATH] [-o PATH]

mypy/test/data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def expand_errors(input: List[str], output: List[str], fnam: str) -> None:
479479
# The first in the split things isn't a comment
480480
for possible_err_comment in input[i].split(' # ')[1:]:
481481
m = re.search(
482-
'^([ENW]):((?P<col>\d+):)? (?P<message>.*)$',
482+
r'^([ENW]):((?P<col>\d+):)? (?P<message>.*)$',
483483
possible_err_comment.strip())
484484
if m:
485485
if m.group(1) == 'E':
@@ -572,11 +572,11 @@ def split_test_cases(parent: 'DataSuiteCollector', suite: 'DataSuite',
572572
"""
573573
with open(file, encoding='utf-8') as f:
574574
data = f.read()
575-
cases = re.split('^\[case ([a-zA-Z_0-9]+)'
576-
'(-writescache)?'
577-
'(-only_when_cache|-only_when_nocache)?'
578-
'(-skip)?'
579-
'\][ \t]*$\n', data,
575+
cases = re.split(r'^\[case ([a-zA-Z_0-9]+)'
576+
r'(-writescache)?'
577+
r'(-only_when_cache|-only_when_nocache)?'
578+
r'(-skip)?'
579+
r'\][ \t]*$\n', data,
580580
flags=re.DOTALL | re.MULTILINE)
581581
line_no = cases[0].count('\n') + 1
582582
for i in range(1, len(cases), 5):

mypy/test/testmerge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def build(self, source: str) -> Optional[BuildResult]:
114114
result = build.build(sources=[BuildSource(main_path, None, None)],
115115
options=options,
116116
alt_lib_path=test_temp_dir)
117-
except CompileError as e:
117+
except CompileError:
118118
# TODO: Is it okay to return None?
119119
return None
120120
return result

mypy/test/typefixture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TypeFixture:
2020
The members are initialized to contain various type-related values.
2121
"""
2222

23-
def __init__(self, variance: int=COVARIANT) -> None:
23+
def __init__(self, variance: int = COVARIANT) -> None:
2424
# The 'object' class
2525
self.oi = self.make_type_info('builtins.object') # class object
2626
self.o = Instance(self.oi, []) # object

mypy/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def get_class_descriptors(cls: 'Type[object]') -> Sequence[str]:
209209
return fields_cache[cls]
210210

211211

212-
def replace_object_state(new: object, old: object, copy_dict: bool=False) -> None:
212+
def replace_object_state(new: object, old: object, copy_dict: bool = False) -> None:
213213
"""Copy state of old node to the new node.
214214
215215
This handles cases where there is __dict__ and/or attribute descriptors

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ exclude =
3535
# W601: has_key() deprecated (false positives)
3636
# E701: multiple statements on one line (colon) (we use this for classes with empty body)
3737
# W503: line break before binary operator
38+
# W504: line break after binary operator
3839
# E704: multiple statements on one line (def)
3940
# E402: module level import not at top of file
4041
# B3??: Python 3 compatibility warnings
4142
# B006: use of mutable defaults in function signatures
4243
# B007: Loop control variable not used within the loop body.
43-
ignore = E251,E128,F401,W601,E701,W503,E704,E402,B3,B006,B007
44+
ignore = E251,E128,F401,W601,E701,W503,W504,E704,E402,B3,B006,B007
4445

4546
[coverage:run]
4647
branch = true

0 commit comments

Comments
 (0)