Skip to content

Implement PEP 696: Type Variable Defaults#245

Closed
yaskhan wants to merge 2 commits intomainfrom
pep-696-defaults-13720066664418113791
Closed

Implement PEP 696: Type Variable Defaults#245
yaskhan wants to merge 2 commits intomainfrom
pep-696-defaults-13720066664418113791

Conversation

@yaskhan
Copy link
Copy Markdown
Owner

@yaskhan yaskhan commented Mar 4, 2026

Implemented support for PEP 696 (Type Variable Defaults) in the Python to V transpiler.

Key changes:

  1. Preprocessor: Added _preprocess_type_parameter_defaults to CompatibilityLayer to support Python 3.13+ syntax [T = int] on older Python versions by mangling it to a parsable format.
  2. Registry: Added generic_info to TranslatorBase to track generic parameters and their defaults for symbols.
  3. Type Mapping: Updated map_python_type_to_v and its internal AST visitor to apply defaults when a generic type is used with missing or partial arguments.
  4. Mixins: Updated ClassesMixin, FunctionsMixin, and TypeAliasMixin to extract and register default type parameters.
  5. Variable Initialization: Updated AnnotationsMixin to correctly zero-initialize variables of generic types that now resolve to concrete V types due to default application.
  6. Tests: Added py2v_transpiler/tests/test_pep696.py covering various use cases.

Note: There is a known regression in advanced PEP 695 Callable unpacking tests that needs further investigation.

Fixes #158


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

- Added a preprocessor to CompatibilityLayer to mangle PEP 696 [T = Default] syntax into PEP 695 compatible [T: __py2v_def__Default] on Python < 3.13.
- Updated TranslatorBase to maintain a generic_info registry for classes, functions, and type aliases.
- Enhanced map_python_type_to_v and _map_ast_type in py2v_transpiler/models/v_types.py to support PEP 696 defaults by filling in missing generic arguments.
- Updated translator mixins to leverage the new default-aware type mapping.
- Improved variable initialization in AnnotationsMixin to correctly handle generic types with applied defaults.
- Added comprehensive tests for PEP 696 features.

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.

- Added support for PEP 696 type parameter defaults in classes, functions, and type aliases.
- Implemented a preprocessor in CompatibilityLayer to handle Python 3.13+ generic default syntax on older versions.
- Fixed a regression in the preprocessor that incorrectly mangled keyword arguments (e.g., file=sys.stderr).
- Enhanced map_python_type_to_v to apply defaults when generic types are used with missing arguments.
- Updated translator mixins to support the new default-aware type mapping.
- Improved zero-initialization of variables with generic types in AnnotationsMixin.
- Added comprehensive unit tests for PEP 696 features.

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 #245 has conflicts that needs to be resolved.
You can resolve it at codeinput: f66d1bcf-7eb0-4e36-8475-69e455a888c6.

@yaskhan yaskhan closed this Mar 15, 2026
@yaskhan yaskhan deleted the pep-696-defaults-13720066664418113791 branch March 16, 2026 20:17
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 PEP 696: Type Variable Defaults

1 participant