Skip to content

Clean up redundant Python codegen lambdas#1104

Merged
stephentoub merged 1 commit intomainfrom
stephentoub/sync-python-generator-1103
Apr 17, 2026
Merged

Clean up redundant Python codegen lambdas#1104
stephentoub merged 1 commit intomainfrom
stephentoub/sync-python-generator-1103

Conversation

@stephentoub
Copy link
Copy Markdown
Collaborator

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

  • add a post-processing pass in scripts/codegen/python.ts that rewrites lambda x: callable(x) to the direct callable when it is safe to do so
  • update the Python codegen test to expect the simplified form and add a regression test for string, list, and nested dataclass callables
  • regenerate python/copilot/generated/session_events.py so the checked-in generated output matches the new generator

Notes

  • this is a generator/output cleanup only; it does not change the protocol schema or runtime behavior
  • python/copilot/generated/rpc.py did not change with the current schema

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>
@stephentoub stephentoub requested a review from a team as a code owner April 17, 2026 18:16
Copilot AI review requested due to automatic review settings April 17, 2026 18:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 collapse lambda x: callable(x) into callable when 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.py to 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

@stephentoub stephentoub enabled auto-merge April 17, 2026 18:42
@github github deleted a comment from stomde Apr 17, 2026
@stephentoub stephentoub disabled auto-merge April 17, 2026 19:58
@stephentoub stephentoub merged commit 48e244d into main Apr 17, 2026
37 of 39 checks passed
@stephentoub stephentoub deleted the stephentoub/sync-python-generator-1103 branch April 17, 2026 19:58
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.

2 participants