Skip to content

Conversation

plfj
Copy link

@plfj plfj commented Sep 6, 2025

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
Copy link
Author

plfj commented Sep 6, 2025

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
Copy link
Author

plfj commented Sep 6, 2025

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

@plfj
Copy link
Author

plfj commented Sep 7, 2025

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
Copy link
Author

plfj commented Sep 8, 2025

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

@whoami730
Copy link
Contributor

Note on title - there is no MAKE_CLOSURE_A opcode

@plfj
Copy link
Author

plfj commented Sep 20, 2025

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 plfj requested review from greenozon and whoami730 September 26, 2025 10:02
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.

3 participants