Skip to content

Commit

Permalink
FIX #7: add async with support and with variables nodes validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Илья Лебедев committed Jan 12, 2020
1 parent cb988bc commit d29f81f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion flake8_expression_complexity/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.5'
__version__ = '0.0.6'
11 changes: 7 additions & 4 deletions flake8_expression_complexity/utils/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@

def iterate_over_expressions(node: ast.AST) -> Iterable[ast.AST]:
additionals_subnodes_info: List[Tuple[Tuple, Callable]] = [
((ast.If, ast.While), lambda n: n.test),
((ast.For, ), lambda n: n.iter),
((ast.If, ast.While), lambda n: [n.test]),
((ast.For, ), lambda n: [n.iter]),
((ast.With, ast.AsyncWith), lambda n: [s.context_expr for s in n.items]),
]
nodes_with_subnodes = (
ast.FunctionDef, ast.AsyncFunctionDef,
ast.If, ast.For, ast.Module,
ast.ClassDef, ast.Try, ast.With, ast.While,
ast.ClassDef, ast.Try, ast.With, ast.AsyncWith,
ast.While,
)
for bases, subnodes_getter in additionals_subnodes_info:
if isinstance(node, bases):
yield subnodes_getter(node)
for subitem in subnodes_getter(node):
yield subitem
nodes_to_iter = (
_get_try_node_children(node)
if isinstance(node, ast.Try)
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mypy==0.740
mypy-extensions==0.4.1
typing==3.6.4
typing-extensions==3.7.4
flake8==3.7.8
flake8==3.7.9
flake8-annotations-complexity==0.0.2
flake8-blind-except==0.1.1
flake8-broken-line==0.1.1
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ignore = D, W503
max-line-length = 100
use_class_attributes_order_strict_mode = True
max_function_length = 50
max-complexity = 6
max-complexity = 7


[mypy]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

def test_fails():
errors = run_validator_for_test_file('long_expressions.py', max_expression_compexity=3)
assert len(errors) == 3
assert len(errors) == 4
7 changes: 6 additions & 1 deletion tests/test_files/long_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ async def foo():


async def bar():
return 'bar'
async with foo:
return 'bar'


weird_container = []
sublist = weird_container[10:datetime.datetime.today(), None]


with weird_container[10:str(datetime.datetime.today().date())[:100], None]:
pass

0 comments on commit d29f81f

Please sign in to comment.