pycdc icon indicating copy to clipboard operation
pycdc copied to clipboard

Version-aware MAKE_FUNCTION_A and MAKE_CLOSURE_A support

Open plfj opened this issue 3 months ago • 7 comments

Summary

This PR replaces the existing counts-only implementation of MAKE_FUNCTION_A and MAKE_CLOSURE_A with a version-aware handler that supports all Python 3.x releases up to 3.14+.

Previous behavior

  • Only supported operand format with defCount and kwDefCount.
  • Did not handle annotations, closure cells, or flag-based operand encodings.
  • Effective for Python ≤ 3.3 (and partially 3.4), but failed on later versions.

New behavior

  • Python ≤ 3.3
    • Retains counts-based handling (positional + keyword defaults).
  • Python 3.4–3.5
    • Adds annotation support and adjusts argument default order (kw before positional).
  • Python 3.6–3.9
    • Switches to flag-based operand encoding.
    • Handles closure cells, annotation dicts, keyword defaults, and positional defaults.
  • Python 3.10–3.13
    • Supports PEP 563 deferred evaluation of annotations (annotation may be dict or string).
  • Python ≥ 3.14
    • Adds support for new operand flag (0x10), ensuring forward compatibility.

Outcome

  • Functions are now reconstructed consistently across all supported Python versions.
  • AST generation correctly accounts for defaults, keyword defaults, annotations, and closure cells.
  • Backward compatibility with earlier operand encoding is preserved.

plfj avatar Sep 06 '25 06:09 plfj

Dear @greenozon and @zrax,

I would greatly appreciate it if you could review this pull request at your convenience. Your insights and feedback will be very valuable in ensuring the quality and reliability of these changes.

Thank you in advance for your time and consideration.

plfj avatar Sep 06 '25 06:09 plfj

Thank you very much for your review, @greenozon — your feedback is greatly appreciated.

plfj avatar Sep 06 '25 16:09 plfj

Dear @whoami730 , I would greatly appreciate it if you could review this pull request at your convenience. Your insights and feedback will be very valuable in ensuring the quality and reliability of these changes.

Thank you in advance for your time and consideration.

plfj avatar Sep 07 '25 09:09 plfj

Hello @whoami730, could you kindly assist me in fixing the tokenized files? I would greatly appreciate your help.

plfj avatar Sep 08 '25 07:09 plfj

Note on title - there is no MAKE_CLOSURE_A opcode

whoami730 avatar Sep 11 '25 09:09 whoami730

Dear @zrax, @greenozon, and @whoami730,

I would greatly appreciate it if you could review this pull request at your convenience. Your insights and feedback will be very valuable in ensuring the quality and reliability of these changes.

Thank you in advance for your time and consideration.

plfj avatar Sep 20 '25 12:09 plfj

Sorry for the delay, I don't have much time to work on pycdc these days.

This change adds a bunch of new features, but the only test added is fairly trivial... Is there a plan to add at least basic tests for some of the new functionality?

zrax avatar Oct 21 '25 22:10 zrax