Skip to content
This repository was archived by the owner on Oct 1, 2019. It is now read-only.

Commit dfb3f69

Browse files
ryanashcraftpatrick91
authored andcommitted
Fix ordering of starred, kwargs in calls for python 2 (#102)
* Add broken mixed call test for #101 * Fix starred args and kwargs ordering in calls for python 2
1 parent 335b70b commit dfb3f69

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/printer/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,19 +639,21 @@ function genericPrint(path, options, print) {
639639
case "Call": {
640640
let args = [];
641641

642-
// python 2
642+
args = args.concat(path.map(print, "args"));
643+
644+
// `starargs` and `kwargs` were removed in Python 3.5.
645+
// Instead starred arguments exist in `args` and `kwargs` in `keywords`.
643646

644647
if (n.starargs) {
645648
args.push(concat(["*", path.call(print, "starargs")]));
646649
}
647650

651+
args = args.concat(path.map(print, "keywords"));
652+
648653
if (n.kwargs) {
649654
args.push(concat(["**", path.call(print, "kwargs")]));
650655
}
651656

652-
args = args.concat(path.map(print, "args"));
653-
args = args.concat(path.map(print, "keywords"));
654-
655657
return concat([path.call(print, "func"), "(", join(", ", args), ")"]);
656658
}
657659

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`call_mixed.py 1`] = `
4+
args = (1, 2, 3, 4)
5+
kwargs = {'var_f': 7}
6+
my_func_with_many_args(0, *args, var_e=5, var_j=6, **kwargs)
7+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8+
args = (1, 2, 3, 4)
9+
kwargs = {"var_f": 7}
10+
my_func_with_many_args(0, *args, var_e=5, var_j=6, **kwargs)
11+
12+
`;
13+
14+
exports[`call_mixed.py 2`] = `
15+
args = (1, 2, 3, 4)
16+
kwargs = {'var_f': 7}
17+
my_func_with_many_args(0, *args, var_e=5, var_j=6, **kwargs)
18+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19+
args = (1, 2, 3, 4)
20+
kwargs = {"var_f": 7}
21+
my_func_with_many_args(0, *args, var_e=5, var_j=6, **kwargs)
22+
23+
`;

tests/python_call_mixed/call_mixed.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
args = (1, 2, 3, 4)
2+
kwargs = {'var_f': 7}
3+
my_func_with_many_args(0, *args, var_e=5, var_j=6, **kwargs)

tests/python_call_mixed/jsfmt.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
run_spec(__dirname, ["python"], { pythonVersion: "2" });
2+
run_spec(__dirname, ["python"], { pythonVersion: "3" });

0 commit comments

Comments
 (0)