Skip to content

Implement statically typed *args and **kwargs#248

Open
yaskhan wants to merge 3 commits intomainfrom
typed-variadic-args-16994163937431969794
Open

Implement statically typed *args and **kwargs#248
yaskhan wants to merge 3 commits intomainfrom
typed-variadic-args-16994163937431969794

Conversation

@yaskhan
Copy link
Copy Markdown
Owner

@yaskhan yaskhan commented Mar 4, 2026

This PR implements statically typed variadic arguments in the Python-to-V transpiler.

Key changes:

  • Modified FunctionsMixin in py2v_transpiler/core/translator/functions.py to correctly handle explicit annotations and inferred types for *args and **kwargs.
  • Updated *args handling to strip V array brackets [] and emit variadic syntax ...T.
  • Updated **kwargs handling to ensure it is always emitted as a map (map[string]T).
  • Changed the default type for unannotated variadics from int/map[string]string to Any/map[string]Any.
  • Enhanced the Mypy plugin in py2v_transpiler/core/mypy_plugin.py to store inferred types by simple variable name, enabling more reliable type lookups during translation.
  • Updated py2v_transpiler/models/v_types.py to support lowercase dict and tuple identifiers (often emitted by Mypy) and to strip builtins. prefixes.
  • Added comprehensive test cases in py2v_transpiler/tests/translator/test_variadic_typing.py and updated existing tests in test_varargs.py and test_kwargs_def.py to reflect the improved defaults.

Fixes #178


PR created automatically by Jules for task 16994163937431969794 started by @yaskhan

Emit homogeneous V arrays/maps for typed variadic arguments.
Detect *args: T and similar annotations and emit as ...T instead of ...Any.
Handle **kwargs: T as map[string]T instead of map[string]Any.
Default untyped variadics to ...Any and map[string]Any.
Improve Mypy plugin to store types by simple name for better inference lookup.
Update v_types.py to handle lowercase dict and tuple identifiers from Mypy.

Co-authored-by: yaskhan <3676373+yaskhan@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@code-input
Copy link
Copy Markdown

code-input bot commented Mar 4, 2026

Pull request #248 has conflicts that needs to be resolved.
You can resolve it at codeinput: 43e65b05-72ca-42cf-952e-c807313effcc.

yaskhan and others added 2 commits March 5, 2026 03:41
- Modified `FunctionsMixin` to handle explicit annotations and inferred types for `*args` and `**kwargs`.
- Updated `*args` to emit `...T` and `**kwargs` to emit `map[string]T`.
- Fixed `NameError` and key mismatch in `mypy_plugin.py`.
- Enhanced `v_types.py` for Mypy's lowercase `dict`/`tuple` and `builtins.` stripping.
- Improved `CallsMixin` to correctly transpile `bytes`, `bytearray`, and `memoryview`.
- Fixed PEP 695 test expectation for `tuple[*Ts]`.
- Added `test_variadic_typing.py` and updated existing variadic tests.

Co-authored-by: yaskhan <3676373+yaskhan@users.noreply.github.com>
@code-input
Copy link
Copy Markdown

code-input bot commented Mar 4, 2026

Pull request #248 has conflicts that needs to be resolved.
You can resolve it at codeinput: ded6b76f-8cdf-43f6-ae04-81974d4eb36f.

@yaskhan yaskhan force-pushed the main branch 2 times, most recently from 592f0b8 to db8e305 Compare March 18, 2026 16:30
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.

Implement Statically Typed *args and **kwargs

1 participant