Skip to content

Implement Variance Support for PEP 695 Type Parameters#232

Closed
yaskhan wants to merge 2 commits intomainfrom
feat/pep695-variance-support-15320403030881130028
Closed

Implement Variance Support for PEP 695 Type Parameters#232
yaskhan wants to merge 2 commits intomainfrom
feat/pep695-variance-support-15320403030881130028

Conversation

@yaskhan
Copy link
Copy Markdown
Owner

@yaskhan yaskhan commented Mar 4, 2026

Implement support for explicit variance modifiers (+T, -T) in PEP 695 type parameter syntax. The modifiers are preserved as metadata comments in the generated V code, providing future-proofing and documentation for V's invariant generics. The implementation includes a robust preprocessing layer to handle multi-line headers and async functions.

Fixes #198


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

Implemented support for explicit covariance (+T) and contravariance (-T)
modifiers in PEP 695 type parameter syntax.

Key changes:
- Added `_preprocess_pep695_variance` to `CompatibilityLayer` to strip
  variance modifiers before AST parsing, ensuring compatibility with
  standard Python 3.12+ while preserving metadata.
- Updated `PyASTParser` to propagate variance information from the
  preprocessor to AST nodes.
- Modified `ClassesMixin`, `FunctionsMixin`, and `TypeAliasMixin` to
  emit variance modifiers as `@variance` comments in the generated V code.
- Added comprehensive unit tests in `py2v_transpiler/tests/test_variance.py`.
- Updated `README.md` to document variance support and the invariance of
  V generics.
- Improved preprocessor to handle `async def` and multi-line headers.
- Fixed existing compatibility tests to work with the updated preprocessor.
- Verified that Mypy correctly detects variance violations in the
  original source code.

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 #232 has conflicts that needs to be resolved.
You can resolve it at codeinput: 196ac700-a6c6-4393-b009-ab4b381f9490.

Completed the implementation with several improvements:
- Robust preprocessor in `CompatibilityLayer` using `re.finditer` and bracket counting
  to support multi-line headers and `async def`.
- Attached variance metadata to AST nodes in `PyASTParser`.
- Updated `ClassesMixin`, `FunctionsMixin`, and `TypeAliasMixin` to emit
  variance information as `@variance` comments in V code.
- Added comprehensive unit tests in `py2v_transpiler/tests/test_variance.py`.
- Updated `README.md` and `TODO.md`.
- Fixed existing compatibility tests.
- Verified that all 531 tests pass.

Co-authored-by: yaskhan <3676373+yaskhan@users.noreply.github.com>
@yaskhan yaskhan closed this Mar 15, 2026
@yaskhan yaskhan deleted the feat/pep695-variance-support-15320403030881130028 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 Variance Support for PEP 695 Type Parameters

1 participant