Skip to content

Fix MAKE_FUNCTION default args for py 3.4 #538

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

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

Conversation

CarrBen
Copy link

@CarrBen CarrBen commented Feb 11, 2025

Some changes for the handling of MAKE_FUNCTION operand & arguments in py3.0-3.5 that I discovered while updating MAKE_FUNCTION to support the changed operand for py3.6+ (planning to raise that as another PR).

MAKE_FUNCTION Python 3.0 Docs
MAKE_FUNCTION Python 3.4 Docs

Summary

  • Update compiled test_functions_py3 for py 3.4 to match input .py
  • Update tokenized test_functions_py3 to match input .py
  • Update compiled test_functions_py3 for py 3.0 to match input .py
  • Updated handling of Kwarg pairs for all versions
  • Changed order of pops to take Kwargs first for py3.4+
  • Added code to pop & ignore type annotations

Tests

The test_functions_py3 tests were passing for 3.0 & 3.4, but the .pyc's & tokenized files were missing a number of additional cases that were present in the input .py
The changes to the .pyc's & tokenized output are to include these additional cases. I used the token_dump and pymultic scripts for this, with a slight modification to use -alpine containers in pymultic.

Wrong Order of Arg Defaults

With the current master, pycdc produced this output for the last test case on py3.4.

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

However, this is the input

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

With the issue seeming to be the changed order of Position & Kwarg defaults on the stack between 3.3 & newer.

Incorrect Popping of Kwarg Defaults

I also added an additional test case with multiple Kwargs:

def x7e(foo = 1, *, bar = 2, baz = 3, **kwargs):
    pass

Again with the current master this fails for py3.0

def x7e(foo = 1, *, bar = 'baz', baz = 3, **kwargs):
    pass

and for py3.4

def x7e(foo = 3, *, bar = 2, baz = 'baz', **kwargs):
    pass

Which seems to be due to only 1 item being popped from the stack per Kwarg, when there are actually 2 (value followed by key).

Related Issues
#91 ?

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

Successfully merging this pull request may close these issues.

1 participant