Clean up redundant Python codegen lambdas#1104
Merged
stephentoub merged 1 commit intomainfrom Apr 17, 2026
Merged
Conversation
Unwrap redundant passthrough lambdas in the Python generator, add a regression test, and regenerate the Python session events output. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR cleans up Python code generation output by removing redundant passthrough lambdas (e.g., lambda x: from_str(x) → from_str) to reduce noise in generated code and avoid static analysis “unnecessary lambda” findings, without changing the intended parsing/serialization behavior.
Changes:
- Added a Python codegen post-processing pass (
unwrapRedundantPythonLambdas) to collapselambda x: callable(x)intocallablewhen safe. - Updated/extended the Node-based Python codegen tests to assert the simplified output and cover string/list/nested-dataclass callables.
- Regenerated
python/copilot/generated/session_events.pyto reflect the new generator output.
Show a summary per file
| File | Description |
|---|---|
| scripts/codegen/python.ts | Adds the lambda-unwrapping post-process and applies it to session-events and RPC generation output. |
| python/copilot/generated/session_events.py | Regenerated output showing collapsed redundant lambdas throughout the generated dataclass converters. |
| nodejs/test/python-codegen.test.ts | Updates an existing expectation and adds a regression test validating the lambda unwrapping behavior. |
Copilot's findings
- Files reviewed: 2/3 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This copies the Python generator cleanup from #1103 into this branch. It removes redundant passthrough lambdas from generated Python so the output is cleaner and avoids unnecessary-lambda static analysis noise without changing behavior.
What changed
scripts/codegen/python.tsthat rewriteslambda x: callable(x)to the direct callable when it is safe to do sopython/copilot/generated/session_events.pyso the checked-in generated output matches the new generatorNotes
python/copilot/generated/rpc.pydid not change with the current schema