Version-aware MAKE_FUNCTION_A and MAKE_CLOSURE_A support
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.
- Adds support for new operand flag (
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.
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.
Thank you very much for your review, @greenozon — your feedback is greatly appreciated.
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.
Hello @whoami730, could you kindly assist me in fixing the tokenized files? I would greatly appreciate your help.
Note on title - there is no MAKE_CLOSURE_A opcode
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.
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?