Skip to content

Support edges based on TypeVar constraints/bounds #117

@jayqi

Description

@jayqi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions