erdantic
erdantic copied to clipboard
Support edges based on TypeVar constraints/bounds
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.