Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 3.6+ default arguments #391

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

ptrstr
Copy link

@ptrstr ptrstr commented Oct 18, 2023

Fixes #138.
Fixes #155.
Fixes #370.

Python 3.6 moved from pushing the default arguments individually to the stack to pushing a tuple with them.

Modifications:

  • LOAD_CLOSURE should push junk to the stack instead of skipping, as MAKE_FUNCTION with operand 8 will have a structure like follows:
 10           0 LOAD_CONST               4 (('',))
              2 LOAD_CLOSURE             0 (digestmod)
              4 BUILD_TUPLE              1
              6 LOAD_CONST               2 (<code object <lambda> at 0x5629f4e717a0, file "example.py", line 10>)
              8 LOAD_CONST               3 ('__init__.<locals>.<lambda>')
             10 MAKE_FUNCTION            9
  • MAKE_FUNCTION will handle default arguments of type 1, 2 and 8 (4 is about type hints).

Copy link
Owner

@zrax zrax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be good to add or update tests for this case

ASTree.cpp Outdated Show resolved Hide resolved
ASTree.cpp Outdated Show resolved Hide resolved
@ptrstr
Copy link
Author

ptrstr commented Oct 19, 2023

It would also be good to add or update tests for this case

The tests looked a bit strange from my observations (Python code wasn't the same as the expected output).

I rebuilt the .pyc files for the versions that were already there and removed the xfail as now it passed.

Copy link
Owner

@zrax zrax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names of the compiled test files are not correct (unfortunately, it's a bit misleading since the input file is "..._py3", so "test_functions_py3.3.0.pyc" means "test_functions_py3.py for Python 3.0"). Also, when I rebuilt the test files for Python 3.4 (which was one of the original cases included), it appears to have a new failure:

tests/test_functions_py3.3.4.pyc.tok.txt does not match tests/tokenized/test_functions_py3.txt:
--- tests/tokenized/test_functions_py3.txt      2023-10-20 14:05:18.112904714 -0700
+++ tests/test_functions_py3.3.4.pyc.tok.txt    2023-10-20 14:07:39.786332445 -0700
@@ -58,7 +58,7 @@
 <INDENT>
 pass <EOL>
 <OUTDENT>
-def x6d ( foo = 1 , * , bar = 2 ) : <EOL>
+def x6d ( foo = 2 , * , bar = 'bar' ) : <EOL>
 <INDENT>
 pass <EOL>
 <OUTDENT>
@@ -74,6 +74,6 @@
 <INDENT>
 pass <EOL>
 <OUTDENT>
-def x7d ( foo = 1 , * , bar = 2 , ** kwargs ) : <EOL>
+def x7d ( foo = 2 , * , bar = 'bar' , ** kwargs ) : <EOL>
 <INDENT>
 pass <EOL>

@CosminPerRam
Copy link

hey, any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants