Skip to content

Support or work-around for alternative base class declaration #529

@dimaqq

Description

@dimaqq

Question

We've got some code that has to support both pydantic 1 and 2 for historical reasons.

It looks like this:

PYDANTIC_IS_V1 = int(pydantic.version.VERSION.split(".")[0]) < 2
if PYDANTIC_IS_V1:
    class DatabagModel(BaseModel):  # type: ignore
        ...
else:
    class DatabagModel(BaseModel):
        ...

Attempting to use this model is rejected by ty:

warning[unsupported-base]: Unsupported class base with type `<class 'DatabagModel'> | <class 'DatabagModel'>`
   --> lib/charms/traefik_k8s/v2/ingress.py:238:30
    |
238 | class IngressRequirerAppData(DatabagModel):
    |                              ^^^^^^^^^^^^

Version

ty 0.0.1-alpha.7 (afb20f6 2025-05-26)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for support or clarificationset-theoretic typesunions, intersections and more

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions