Skip to content

Preserve keyword calls in bounded expression reconstruction - #16

Open
EiNSTeiN- wants to merge 2 commits into
ejfkdev:mainfrom
EiNSTeiN-:fix/expression-keyword-calls
Open

EiNSTeiN- wants to merge 2 commits into
ejfkdev:mainfrom
EiNSTeiN-:fix/expression-keyword-calls

Conversation

@EiNSTeiN-

Copy link
Copy Markdown

I am opening this PR to reconstruct named-argument calls in pycdc's bounded expression walker while preserving their enclosing call. The code below currently produces incomplete output:

def select(value, build, other):
    return build("reject" if value else "accept", amount=0)

The incorrect output calls None on one branch:

def select(value, build, other):
    if value:
        return build("reject", amount=0)
    return None("accept", amount=0)

The main parser supports named calls, but its bounded expression walker lacks CALL_KW support. The added handler reads the keyword-name tuple, checks its string entries and argument counts, separates positional from named arguments, and consumes the callable/NULL marker in the existing stack convention. This retains keyword names and argument evaluation order instead of turning the call into an unparseable region or a wrong positional call.

The ternary merger must also retain a keyword-bearing call when merging its argument values. It matches keyword names and order and includes their values alongside positional values in its single-slot merge. This supports both a conditional positional argument and a conditional keyword argument:

build("prefix", amount=0 if value else 1)
build(0 if value else 1, amount=value)

An arm-local callable or argument prefix must not be mistaken for a value preloaded before the condition. The bounded merger declines that shape rather than moving callable resolution or argument evaluation across the truth test.

CALL_KW is introduced in Python 3.13; the added decoding applies to that opcode layout.

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