Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename models in field annotations #27

Merged
merged 3 commits into from Mar 25, 2024
Merged

Conversation

lmmx
Copy link
Owner

@lmmx lmmx commented Mar 25, 2024

As suggested in pydantic/pydantic#9093

Aaa: Aaa = None seems to be the same as #8243 (comment), and can be very misleading as the Aaa annotation will take the value of None.

This fix generates a new name assignment after each model declaration, and these names are used in the models as field annotations. For example the Crowding: CrowdingModel annotation of the Identifier model class in the Journey codegen'd module:

class Crowding(BaseModel):
    """
    Autogenerated from Journey::Tfl.Api.Presentation.Entities.Crowding
    """

    model_config = ConfigDict(
        alias_generator=AliasGenerator(validation_alias=to_camel_case),
    )

    PassengerFlows: list["PassengerFlowModel"]
    TrainLoadings: list["TrainLoadingModel"]
    _source_schema_name: str = PrivateAttr(default='Journey')
    _component_schema_name: str = PrivateAttr(default='Tfl-9')


CrowdingModel = Crowding


class Identifier(BaseModel):
    """
    Autogenerated from Journey::Tfl.Api.Presentation.Entities.Identifier
    """

    model_config = ConfigDict(
        alias_generator=AliasGenerator(validation_alias=to_camel_case),
    )

    Id: str = None
    Name: str = None
    Uri: str = None
    FullName: str = None
    Type: str = None
    Crowding: CrowdingModel = None
    RouteType: str = None
    Status: str = None
    _source_schema_name: str = PrivateAttr(default='Journey')
    _component_schema_name: str = PrivateAttr(default='Tfl-10')

IdentifierModel = Identifier

@lmmx lmmx added the bug Something isn't working label Mar 25, 2024
@lmmx lmmx self-assigned this Mar 25, 2024
@lmmx
Copy link
Owner Author

lmmx commented Mar 25, 2024

Published to PyPI

@lmmx lmmx merged commit 8ee8c12 into master Mar 25, 2024
1 check passed
@lmmx lmmx deleted the rename-models-in-field-annotations branch March 25, 2024 09:24
@lmmx lmmx mentioned this pull request Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pydantic field names annotated as a model class name that matches
1 participant