Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 394d893

Browse files
authored
Add a flake8 configuration and fix lint errors (mypyc/mypyc#98)
Fixes mypyc/mypyc#97.
1 parent 75cd2ab commit 394d893

16 files changed

Lines changed: 115 additions & 55 deletions

conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
pytest_plugins = [
22
'mypy.test.data',
33
]
4+
5+
46
# This function name is special to pytest. See
57
# http://doc.pytest.org/en/latest/writing_plugins.html#initialization-command-line-and-configuration-hooks
68
def pytest_addoption(parser)-> None:

mypyc/analysis.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def get_cfg(blocks: List[BasicBlock]) -> CFG:
4949
label = block.label
5050
last = block.ops[-1]
5151
if isinstance(last, Branch):
52-
succ = [last.true, last.false] # TODO: assume 1:1 correspondence between block index
53-
# and label
52+
# TODO: assume 1:1 correspondence between block index and label
53+
succ = [last.true, last.false]
5454
elif isinstance(last, Goto):
5555
succ = [last.label]
5656
else:
@@ -68,6 +68,7 @@ def get_cfg(blocks: List[BasicBlock]) -> CFG:
6868

6969
AnalysisDict = Dict[Tuple[Label, int], Set[T]]
7070

71+
7172
class AnalysisResult(Generic[T]):
7273
def __init__(self, before: AnalysisDict[T], after: AnalysisDict[T]) -> None:
7374
self.before = before
@@ -76,6 +77,7 @@ def __init__(self, before: AnalysisDict[T], after: AnalysisDict[T]) -> None:
7677
def __str__(self) -> str:
7778
return 'before: %s\nafter: %s\n' % (self.before, self.after)
7879

80+
7981
GenAndKill = Tuple[Set[Value], Set[Value]]
8082

8183

@@ -236,6 +238,7 @@ def visit_assign(self, op: Assign) -> GenAndKill:
236238
return set(), {op.dest}
237239
return set(), set()
238240

241+
239242
def analyze_borrowed_arguments(
240243
blocks: List[BasicBlock],
241244
cfg: CFG,
@@ -269,6 +272,7 @@ def visit_register_op(self, op: RegisterOp) -> GenAndKill:
269272
def visit_assign(self, op: Assign) -> GenAndKill:
270273
return set(), {op.dest}
271274

275+
272276
def analyze_undefined_regs(blocks: List[BasicBlock],
273277
cfg: CFG,
274278
env: Environment,
@@ -369,7 +373,7 @@ def run_analysis(blocks: List[BasicBlock],
369373
opgen, opkill = op.accept(gen_and_kill)
370374
gen = ((gen - opkill) | opgen)
371375
kill = ((kill - opgen) | opkill)
372-
block_gen[block.label] = gen
376+
block_gen[block.label] = gen
373377
block_kill[block.label] = kill
374378

375379
# Set up initial state for worklist algorithm.
@@ -421,8 +425,8 @@ def run_analysis(blocks: List[BasicBlock],
421425
after[label] = new_after
422426

423427
# Run algorithm for each basic block to generate opcode-level sets.
424-
op_before = {} # type: Dict[Tuple[Label, int], Set[T]]
425-
op_after = {} # type: Dict[Tuple[Label, int], Set[T]]
428+
op_before = {} # type: Dict[Tuple[Label, int], Set[T]]
429+
op_after = {} # type: Dict[Tuple[Label, int], Set[T]]
426430
for block in blocks:
427431
label = block.label
428432
cur = before[label]

mypyc/emitclass.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def emit_line() -> None:
118118
methods_name=methods_name,
119119
getseters_name=getseters_name,
120120
init_name=init_name,
121-
))
121+
))
122122
emitter.emit_line()
123123
generate_setup_for_class(cl, setup_name, vtable_name, emitter)
124124
emitter.emit_line()
@@ -324,6 +324,7 @@ def generate_methods_table(cl: ClassIR,
324324
emitter.emit_line('{NULL} /* Sentinel */')
325325
emitter.emit_line('};')
326326

327+
327328
def generate_getseter_declarations(cl: ClassIR, emitter: Emitter) -> None:
328329
for attr, rtype in cl.attributes:
329330
emitter.emit_line('static PyObject *')
@@ -364,12 +365,12 @@ def generate_getter(cl: ClassIR,
364365
emitter: Emitter) -> None:
365366
emitter.emit_line('static PyObject *')
366367
emitter.emit_line('{}({} *self, void *closure)'.format(getter_name(cl.name, attr),
367-
cl.struct_name()))
368+
cl.struct_name()))
368369
emitter.emit_line('{')
369370
emitter.emit_line('if (self->{} == {}) {{'.format(attr, rtype.c_undefined_value()))
370371
emitter.emit_line('PyErr_SetString(PyExc_AttributeError,')
371372
emitter.emit_line(' "attribute {} of {} undefined");'.format(repr(attr),
372-
repr(cl.name)))
373+
repr(cl.name)))
373374
emitter.emit_line('return NULL;')
374375
emitter.emit_line('}')
375376
emitter.emit_inc_ref('self->{}'.format(attr), rtype)

mypyc/emitfunc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def visit_branch(self, op: Branch) -> None:
8989

9090
cond = ''
9191
if op.op == Branch.BOOL_EXPR:
92-
expr_result = self.reg(op.left) # right isn't used
92+
expr_result = self.reg(op.left) # right isn't used
9393
cond = '{}({})'.format(neg, expr_result)
9494
elif op.op == Branch.IS_NONE:
9595
compare = '!=' if op.negated else '=='

mypyc/emitmodule.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ def generate_c_module(self) -> str:
8686
for cl in self.module.classes:
8787
generate_class(cl, self.module_name, emitter)
8888

89-
9089
emitter.emit_line()
9190

9291
self.generate_module_def(emitter)
@@ -138,7 +137,7 @@ def generate_module_def(self, emitter: Emitter) -> None:
138137
for cl in self.module.classes:
139138
type_struct = cl.type_struct
140139
emitter.emit_lines('if (PyType_Ready(&{}) < 0)'.format(type_struct),
141-
' return NULL;')
140+
' return NULL;')
142141
emitter.emit_lines('m = PyModule_Create(&module);',
143142
'if (m == NULL)',
144143
' return NULL;')
@@ -190,7 +189,7 @@ def _toposort_visit(name: str) -> None:
190189
decl.mark = True
191190

192191
for name, marked_declaration in marked_declarations.items():
193-
_toposort_visit(name)
192+
_toposort_visit(name)
194193

195194
return result
196195

mypyc/emitwrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
def wrapper_function_header(fn: FuncIR) -> str:
99
return 'static PyObject *{prefix}{name}(PyObject *self, PyObject *args, PyObject *kw)'.format(
10-
prefix=PREFIX,
11-
name=fn.cname)
10+
prefix=PREFIX,
11+
name=fn.cname)
1212

1313

1414
def generate_wrapper_function(fn: FuncIR, emitter: Emitter) -> None:

mypyc/genops.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def f(x: int) -> int:
1818

1919
from mypy.nodes import (
2020
Node, MypyFile, FuncDef, ReturnStmt, AssignmentStmt, OpExpr, IntExpr, NameExpr, LDEF, Var,
21-
IfStmt, Node, UnaryExpr, ComparisonExpr, WhileStmt, Argument, CallExpr, IndexExpr, Block,
21+
IfStmt, UnaryExpr, ComparisonExpr, WhileStmt, Argument, CallExpr, IndexExpr, Block,
2222
Expression, ListExpr, ExpressionStmt, MemberExpr, ForStmt, RefExpr, Lvalue, BreakStmt,
2323
ContinueStmt, ConditionalExpr, OperatorAssignmentStmt, TupleExpr, ClassDef, TypeInfo,
2424
Import, ImportFrom, ImportAll, DictExpr, StrExpr, CastExpr, TempNode, ARG_POS, MODULE_REF
@@ -147,12 +147,12 @@ def __init__(self, types: Dict[Expression, Type], mapper: Mapper) -> None:
147147
self.continue_gotos = [] # type: List[List[Goto]]
148148

149149
self.mapper = mapper
150-
self.imports = [] # type: List[str]
150+
self.imports = [] # type: List[str]
151151

152152
# Maps unicode literals to the static c name for that literal
153-
self.unicode_literals = {} # type: Dict[str, str]
153+
self.unicode_literals = {} # type: Dict[str, str]
154154

155-
self.current_module_name = None # type: Optional[str]
155+
self.current_module_name = None # type: Optional[str]
156156

157157
def visit_mypy_file(self, mypyfile: MypyFile) -> Value:
158158
if mypyfile.fullname() in ('typing', 'abc'):
@@ -500,7 +500,6 @@ def visit_for_stmt(self, s: ForStmt) -> Value:
500500
assert isinstance(s.index.node, Var)
501501
lvalue_reg = self.environment.add_local(s.index.node, self.node_type(s.index))
502502

503-
504503
condition_block = self.goto_new_block()
505504

506505
# For compatibility with python semantics we recalculate the length
@@ -573,8 +572,8 @@ def binary_op(self,
573572
if (is_subtype(lreg.type, desc.arg_types[0])
574573
and is_subtype(rreg.type, desc.arg_types[1])):
575574
if matching:
576-
assert matching.priority != desc.priority, 'Ambiguous: %s, %s' % (matching,
577-
desc)
575+
assert matching.priority != desc.priority, 'Ambiguous: %s, %s' % (matching,
576+
desc)
578577
if desc.priority > matching.priority:
579578
matching = desc
580579
else:
@@ -665,7 +664,7 @@ def load_static_module_attr(self, expr: RefExpr) -> Value:
665664

666665
def py_call(self, function: Value, args: List[Value],
667666
target_type: RType, line: int) -> Value:
668-
arg_boxes = [self.box(arg) for arg in args] # type: List[Value]
667+
arg_boxes = [self.box(arg) for arg in args] # type: List[Value]
669668
target_box = self.add(PyCall(function, arg_boxes, line))
670669
return self.unbox_or_cast(target_box, target_type, line)
671670

@@ -675,7 +674,7 @@ def py_method_call(self,
675674
args: List[Value],
676675
target_type: RType,
677676
line: int) -> Value:
678-
arg_boxes = [self.box(arg) for arg in args] # type: List[Value]
677+
arg_boxes = [self.box(arg) for arg in args] # type: List[Value]
679678
target_box = self.add(PyMethodCall(obj, method, arg_boxes))
680679
return self.unbox_or_cast(target_box, target_type, line)
681680

@@ -691,7 +690,6 @@ def coerce_native_call_args(self,
691690
coerced_arg_regs.append(self.coerce(reg, arg_type, line))
692691
return coerced_arg_regs
693692

694-
695693
def visit_call_expr(self, expr: CallExpr) -> Value:
696694
if isinstance(expr.analyzed, CastExpr):
697695
return self.translate_cast_expr(expr.analyzed)

mypyc/ops.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def accept(self, visitor: 'RTypeVisitor[T]') -> T:
9797
def c_undefined_value(self) -> str:
9898
return ''
9999

100+
100101
void_rtype = RVoid()
101102

102103

@@ -131,7 +132,8 @@ def accept(self, visitor: 'RTypeVisitor[T]') -> T:
131132
return visitor.visit_rprimitive(self)
132133

133134
def __repr__(self) -> str:
134-
return '<RPrimitive %s>'% self.name
135+
return '<RPrimitive %s>' % self.name
136+
135137

136138
# Used to represent arbitrary objects and dynamically typed values
137139
object_rprimitive = RPrimitive('builtins.object', is_unboxed=False, is_refcounted=True)
@@ -502,12 +504,12 @@ class Branch(Op):
502504
IS_ERROR = 102 # Check for magic c_error_value (works for arbitary types)
503505

504506
op_names = {
505-
INT_EQ: ('==', 'int'),
506-
INT_NE: ('!=', 'int'),
507-
INT_LT: ('<', 'int'),
508-
INT_LE: ('<=', 'int'),
509-
INT_GT: ('>', 'int'),
510-
INT_GE: ('>=', 'int'),
507+
INT_EQ: ('==', 'int'),
508+
INT_NE: ('!=', 'int'),
509+
INT_LT: ('<', 'int'),
510+
INT_LE: ('<=', 'int'),
511+
INT_GT: ('>', 'int'),
512+
INT_GE: ('>=', 'int'),
511513
}
512514

513515
unary_op_names = {
@@ -554,7 +556,7 @@ def to_str(self, env: Environment) -> str:
554556
tb = ' (error at %s:%d)' % self.traceback_entry
555557
fmt = 'if {} goto %l{} else goto %l'.format(cond, tb)
556558
if typ:
557-
fmt += ' :: {}'.format(typ)
559+
fmt += ' :: {}'.format(typ)
558560
return env.format(fmt, self.true, self.false)
559561

560562
def invert(self) -> None:
@@ -1333,7 +1335,7 @@ def visit_unbox(self, op: Unbox) -> T:
13331335
def format_blocks(blocks: List[BasicBlock], env: Environment) -> List[str]:
13341336
lines = []
13351337
for i, block in enumerate(blocks):
1336-
last = i == len(blocks) - 1
1338+
i == len(blocks) - 1
13371339

13381340
lines.append(env.format('%l:', block.label))
13391341
ops = block.ops
@@ -1383,6 +1385,7 @@ def visit_rtuple(self, typ: RTuple) -> T:
13831385
def visit_rvoid(self, typ: RVoid) -> T:
13841386
raise NotImplementedError
13851387

1388+
13861389
# Import various modules that set up global state.
13871390
import mypyc.ops_int
13881391
import mypyc.ops_str

mypyc/ops_int.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from typing import List
22

3-
from mypyc.ops import PrimitiveOp, int_rprimitive, RType, EmitterInterface, OpDescription, ERR_NEVER
3+
from mypyc.ops import (
4+
PrimitiveOp, int_rprimitive, RType, EmitterInterface, OpDescription, ERR_NEVER,
5+
)
46
from mypyc.ops_primitive import binary_op, unary_op, simple_emit
57

68

mypyc/subtype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from mypyc.ops import (
44
RType, ROptional, RInstance, RPrimitive, RTuple, RVoid, RTypeVisitor,
5-
is_bool_rprimitive, is_int_rprimitive, is_tuple_rprimitive, none_rprimitive, is_object_rprimitive
5+
is_bool_rprimitive, is_int_rprimitive, is_tuple_rprimitive, none_rprimitive,
6+
is_object_rprimitive
67
)
78

89

0 commit comments

Comments
 (0)