Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions ASTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1576,13 +1576,36 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
ASTFunction::defarg_t defArgs, kwDefArgs;
const int defCount = operand & 0xFF;
const int kwDefCount = (operand >> 8) & 0xFF;
for (int i = 0; i < defCount; ++i) {
defArgs.push_front(stack.top());
stack.pop();
}
for (int i = 0; i < kwDefCount; ++i) {
kwDefArgs.push_front(stack.top());
stack.pop();
const int annotationCount = (operand >> 16) & 0x7FFF;

/* Docs for 3.3 say KW Pairs come first, but reality disagrees */
if (mod->verCompare(3, 3) <= 0) {
for (int i = 0; i < defCount; ++i) {
defArgs.push_front(stack.top());
stack.pop();
}
/* KW Defaults not mentioned in docs, but they come after the positional args */
for (int i = 0; i < kwDefCount; ++i) {
kwDefArgs.push_front(stack.top());
stack.pop(); // KW Pair object
stack.pop(); // KW Pair name
}
} else {
if(annotationCount) {
stack.pop(); // Tuple of param names for annotations
for (int i = 0; i < annotationCount; ++i) {
stack.pop(); // Pop annotation objects and ignore
}
}
for (int i = 0; i < kwDefCount; ++i) {
kwDefArgs.push_front(stack.top());
stack.pop(); // KW Pair object
stack.pop(); // KW Pair name
}
for (int i = 0; i < defCount; ++i) {
defArgs.push_front(stack.top());
stack.pop();
}
}
stack.push(new ASTFunction(fun_code, defArgs, kwDefArgs));
}
Expand Down
Binary file modified tests/compiled/test_functions_py3.3.0.pyc
Binary file not shown.
Binary file modified tests/compiled/test_functions_py3.3.4.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/input/test_functions_py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ def x7c(foo = 1, *, bar, **kwargs):

def x7d(foo = 1, *, bar = 2, **kwargs):
pass

def x7e(foo = 1, *, bar = 2, baz = 3, **kwargs):
pass
40 changes: 36 additions & 4 deletions tests/tokenized/test_functions_py3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,50 @@ def x4c ( foo , bar = 1 , bla = 2 , * args , ** kwargs ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x5a ( * , bar = 1 ) : <EOL>
def x5a ( * , bar ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x5b ( * , bar = 1 , ** kwargs ) : <EOL>
def x5b ( * , bar = 1 ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x6a ( foo , * , bar = 1 ) : <EOL>
def x5c ( * , bar = 1 , ** kwargs ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x7a ( foo , * , bar = 1 , ** kwargs ) : <EOL>
def x6a ( foo , * , bar ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x6b ( foo , * , bar = 1 ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x6c ( foo = 1 , * , bar ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x6d ( foo = 1 , * , bar = 2 ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x7a ( foo , * , bar , ** kwargs ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x7b ( foo , * , bar = 1 , ** kwargs ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x7c ( foo = 1 , * , bar , ** kwargs ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x7d ( foo = 1 , * , bar = 2 , ** kwargs ) : <EOL>
<INDENT>
pass <EOL>
<OUTDENT>
def x7e ( foo = 1 , * , bar = 2 , baz = 3 , ** kwargs ) : <EOL>
<INDENT>
pass <EOL>