Skip to content

Commit

Permalink
Merge pull request #89 from Carreau/tidy-imports
Browse files Browse the repository at this point in the history
Fix Tidy imports with *args, **kwargs.
  • Loading branch information
scopatz authored Aug 17, 2020
2 parents f16f85e + a49a7b7 commit 657af4c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install:
pip install -U "pexpect>=3.3" pyflakes pytest epydoc rlipython requests jupyter flaky flake8;
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 -U "pexpect>=3.3" pyflakes pytest rlipython requests jupyter flaky flake8 'notebook<6.1' '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 657af4c

Please sign in to comment.