Skip to content

Python Pydantic v2: avoid ordinary class and module TypeVar name shadowing #4083

Description

@coderabbitai

Summary

A generated ordinary class can shadow a same-named module-level TypeVar binding, leaving generic references ambiguous or incorrect in the Python Pydantic v2 SDK output.

Required change

Update the Python Pydantic v2 generator's leaf-global name allocation so generated class/module bindings and allocated module TypeVar names cannot collide. Ensure declarations and all type references use the final, collision-free spelling consistently in both .py and .pyi output.

Affected area

  • baml_language/sdks/python/rust/sdkgen_python_pydantic2/src/leaf.rs
  • Related TypeVar allocation and type translation paths

Acceptance criteria

  • A schema containing an ordinary identifier class and a module-level TypeVar with the same emitted name produces distinct legal Python bindings.
  • References resolve to the intended class or TypeVar in generated runtime and stub output.
  • Regression coverage verifies the generated files are valid and preserves non-colliding output behavior.

Context

Disclosed as an adjacent follow-up during the reserved-word handling work in #4070.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions