Skip to content

Commit d29f81f

Browse files
author
Илья Лебедев
committed
FIX #7: add async with support and with variables nodes validation
1 parent cb988bc commit d29f81f

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.0.5'
1+
__version__ = '0.0.6'

flake8_expression_complexity/utils/ast.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55

66
def iterate_over_expressions(node: ast.AST) -> Iterable[ast.AST]:
77
additionals_subnodes_info: List[Tuple[Tuple, Callable]] = [
8-
((ast.If, ast.While), lambda n: n.test),
9-
((ast.For, ), lambda n: n.iter),
8+
((ast.If, ast.While), lambda n: [n.test]),
9+
((ast.For, ), lambda n: [n.iter]),
10+
((ast.With, ast.AsyncWith), lambda n: [s.context_expr for s in n.items]),
1011
]
1112
nodes_with_subnodes = (
1213
ast.FunctionDef, ast.AsyncFunctionDef,
1314
ast.If, ast.For, ast.Module,
14-
ast.ClassDef, ast.Try, ast.With, ast.While,
15+
ast.ClassDef, ast.Try, ast.With, ast.AsyncWith,
16+
ast.While,
1517
)
1618
for bases, subnodes_getter in additionals_subnodes_info:
1719
if isinstance(node, bases):
18-
yield subnodes_getter(node)
20+
for subitem in subnodes_getter(node):
21+
yield subitem
1922
nodes_to_iter = (
2023
_get_try_node_children(node)
2124
if isinstance(node, ast.Try)

requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mypy==0.740
22
mypy-extensions==0.4.1
33
typing==3.6.4
44
typing-extensions==3.7.4
5-
flake8==3.7.8
5+
flake8==3.7.9
66
flake8-annotations-complexity==0.0.2
77
flake8-blind-except==0.1.1
88
flake8-broken-line==0.1.1

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ignore = D, W503
33
max-line-length = 100
44
use_class_attributes_order_strict_mode = True
55
max_function_length = 50
6-
max-complexity = 6
6+
max-complexity = 7
77

88

99
[mypy]

tests/test_complexity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
def test_fails():
55
errors = run_validator_for_test_file('long_expressions.py', max_expression_compexity=3)
6-
assert len(errors) == 3
6+
assert len(errors) == 4

tests/test_files/long_expressions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ async def foo():
4141

4242

4343
async def bar():
44-
return 'bar'
44+
async with foo:
45+
return 'bar'
4546

4647

4748
weird_container = []
4849
sublist = weird_container[10:datetime.datetime.today(), None]
50+
51+
52+
with weird_container[10:str(datetime.datetime.today().date())[:100], None]:
53+
pass

0 commit comments

Comments
 (0)