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

Support edges based on TypeVar constraints/bounds #117

Open
jayqi opened this issue Apr 11, 2024 · 0 comments
Open

Support edges based on TypeVar constraints/bounds #117

jayqi opened this issue Apr 11, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@jayqi
Copy link
Member

jayqi commented Apr 11, 2024

typing.TypeVar are used for annotating generics, and they can take constraints or bounds.

It probably makes sense to consider those to be an edge. TypeVar annotations are currently not considered a model. To support this, we'll need to special case TypeVar instances and introspect them to get this information.

Example of current behavior:

from typing import Generic, TypeVar, Optional, List

import erdantic as erd
from pydantic import BaseModel, field_validator
import rich

class DataModel(BaseModel):
    """Payload representation."""
    numbers: List[int]
    people: List[str]


DataT = TypeVar('DataT', DataModel, str)


class Response(BaseModel, Generic[DataT]):
    """HTTP Response representation."""

    data: Optional[DataT]

diagram = erd.create(Response)
rich.print(diagram)
#> EntityRelationshipDiagram(models={'__main__.Response': ModelInfo(...)}, edges={})

Desired:

An edge from Response to DataModel should be detected.

@jayqi jayqi added the enhancement New feature or request label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant