Skip to content

Commit

Permalink
Make sure to handle out of order call syntax
Browse files Browse the repository at this point in the history
Also add test.

Call argument order are lost by AST; reorder them.

We also skip this test on earlier version of Python where this syntax is
anyway invalid; and pin promtp_toolkit to <3.0.6 – which we'll
investigate later.

We also make sure to print the pytest 10 slowest test to make sure to
keep an eye on performance.
  • Loading branch information
Carreau committed Aug 13, 2020
1 parent 905aab8 commit 3dc8b99
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ install:
else
pip install -U git+https://github.com/asmeurer/jupyter_console@display_completions;
pip install -U "pexpect>=3.3" pyflakes pytest rlipython requests jupyter flaky flake8 'notebook<6.1';
pip install 'prompt_toolkit<3.0.6';
fi
- if [[ "${DOCS}" == "true" ]]; then
pip install sphinx sphinx_rtd_theme sphinx-autodoc-typehints;
Expand Down
6 changes: 6 additions & 0 deletions lib/python/pyflyby/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def _iter_child_nodes_in_order_internal_1(node):
elif isinstance(node, ast.IfExp):
assert node._fields == ('test', 'body', 'orelse')
yield node.body, node.test, node.orelse
elif isinstance(node, ast.Call):
# call arguments order are lost by ast, re-order them
yield node.func
args = sorted([(k.value.lineno, k.value.col_offset, k) for k in node.keywords]+
[(k.lineno,k.col_offset, k) for k in node.args])
yield [a[2] for a in args]
elif isinstance(node, ast.ClassDef):
if six.PY2:
assert node._fields == ('name', 'bases', 'body', 'decorator_list')
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[pytest]
# IGNORE_EXCEPTION_DETAIL prevents doctest from testing the exception message, but is necessary for Python 2/3 compatibility
doctest_optionflags= ALLOW_UNICODE ALLOW_BYTES IGNORE_EXCEPTION_DETAIL
addopts = --durations=10
filterwarnings =
error::DeprecationWarning
11 changes: 11 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,3 +1295,14 @@ def test_parsable_missing_flags_no_auto_flags_1():
def test_parsable_missing_flags_auto_flags_1():
block = PythonBlock("print(3, file=4)", auto_flags=True)
assert block.parsable

@pytest.mark.skipif(sys.version_info < (3,7), reason='invalid early python syntax')
@pytest.mark.parametrize('input', [
"print(abc=123, *args, **kwargs)",
"print(*args, ijk=123, **kwargs)",
"print(7, *args, **kwargs)",
"print(*args, 12, **kwargs)",
])
def test_parsable_Call_Ast_args_kwargs(input):
block = PythonBlock(input, auto_flags=True)
assert block.annotated_ast_node

0 comments on commit 3dc8b99

Please sign in to comment.