Skip to content

feat(lower): **kwargs normalization — dict[str,T] param + leftover-keyword packing - #121

Draft
espetro wants to merge 1 commit into
masterfrom
work/t2-kwargs
Draft

espetro wants to merge 1 commit into
masterfrom
work/t2-kwargs

Conversation

@espetro

@espetro espetro commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Summary

T2-4 **kwargs normalization (tiered-lowering plan). def f(a, **kwargs: T) lowers like *args: the signature gains a trailing dict[str, T] param flagged kwarg, and _fill_varargs packs leftover named keywords into a dict literal in declaration order. Inside the body kwargs is a normal dict (in, [], .get, iteration over keys).

def total(a: int, **kwargs: int) -> int:
    acc: int = a
    for k in kwargs:
        acc = acc + kwargs[k]
    return acc
total(1, x=2, y=3)  # args -> [1, {"x": 2, "y": 3}]

Shipped path choices:

  • f(**d) call-site unpack stays fenced (PS2002): a dict[str, T] carries no static key set, so we can't prove member binding to declared params or that the remainder fits the kwargs dict.
  • Unannotated def f(**kwargs) keeps the existing PS1202 parameter-form fence; **kwargs: bool fences (dict values of bool are not lowered).
  • *args + **kwargs combos pack both tails; extra positionals without *args keep PS1003.

Tests: tests/test_t2_kwargs.py — IR-shape tests plus oracle-diff vs CPython for capture + iteration + membership. Self-census unchanged (1023 fences / 27 modules): all logic folded into _signature and _fill_varargs, no new annotated defs.

Link to Devin session: https://app.devin.ai/sessions/7578e5a801c14aa8a18e7e7d4b6d2bc5
Open in Devin Desktop: https://app.devin.ai/desktop/session/7578e5a801c14aa8a18e7e7d4b6d2bc5?variant=devin
Requested by: @espetro

… packing

def f(a, **kwargs: T) appends a dict[str, T] param to the signature,
mirroring *args: T -> list[T]. Call sites bind leftover named keywords
into a dict literal in declaration order; kwargs is a normal dict in the
body. f(**d) call-site unpack stays fenced (a dict type carries no
static key set to prove member binding). Unannotated **kwargs keeps the
PS1202 parameter-form fence.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying pyscriptc with  Cloudflare Pages  Cloudflare Pages

Latest commit: 65c917b
Status: ✅  Deploy successful!
Preview URL: https://5141aaff.pyscriptc.pages.dev
Branch Preview URL: https://work-t2-kwargs.pyscriptc.pages.dev

View logs

This branch has not been deployed

No deployments
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