pycdc icon indicating copy to clipboard operation
pycdc copied to clipboard

MAKE_FUNCTION & SET_FUNCTION_ATTRIBUTE_A for 3.13

Open CarrBen opened this issue 3 months ago • 3 comments

DRAFT again...

I'm setting this one up as another Draft, as this builds upon the changes in #539 & #538

I've mainly done this because these things naturally build on top of each other as the Opcode evolve when moving forward through the Python versions. For example, the handling of Function arguments within SET_FUNCTION_ATTRIBUTE_A is the same as MAKE_FUNCTION in Python 3.6-3.12.

Summary

  • Handle the new MAKE_FUNCTION Opcode with the MAKE_FUNCTION_A path.
  • Change MAKE_FUNCTION_A to just push a basic ASTFunction for 3.13, and not do anything with the Operand.
  • Add support for the new SET_FUNCTION_ATTRIBUTE_A Opcode, using code from the previous PR that adds support for 3.6-3.12, to add args & kwargs to the basic ASTFunction pushed by MAKE_FUNCTION_A for 3.13.
  • Update CALL to use the new Stack Order for 3.13.
  • Update LOAD_ATTR with undocumented 3.13 changes.
  • Update the printing of source for NODE_STORE where the destination is a NODE_NAME to hide new 3.13 dunder attributes;
    • __static_attributes__
    • __firstlineno__

Tests

  • Add 3.13 Test case for MAKE_FUNCTION & SET_FUNCTION_ATTRIBUTE.
    • Fails without this PR as MAKE_FUNCTION is unsupported.
    • Based on the test case for the previous MAKE_FUNCTION branches that have some additional args & kwargs functions.
  • Add load_method Test case that fails due to a LOAD_ATTR error in 3.13.
    • Once MAKE_FUNCTION is in place, this test case has lots of None's, where NULLs end up in the wrong place in the method calls at the bottom of the file due to the new CALL Stack Order.

Related Issues

#573 #569 #568 #542 #498

CarrBen avatar Sep 03 '25 21:09 CarrBen

I started looking at CALL_KW and found a bug in my LOAD_ATTR implementation, I put too much inside the if(operand). LOAD_GLOBAL also needs a similar change to put things on the stack in the correct order

CarrBen avatar Sep 03 '25 23:09 CarrBen

Thanks a lot for your contribution @CarrBen .

Unfortunately there seems to be a bug with LOAD_GLOBAL or similar for the below set of py and corresponding pyc file. failing_sample.zip

whoami730 avatar Sep 04 '25 17:09 whoami730

Thanks for taking a look @whoami730, I had spotted an issue with LOAD_ATTR last night, and I'd completely missed updating LOAD_GLOBAL to work with 3.13.

I've pushed a further commit with updates for both Opcodes and it passes your test case on my end.

CarrBen avatar Sep 04 '25 22:09 CarrBen