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 Python 3.12's type statements for declaring type aliases #118

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

Support Python 3.12's type statements for declaring type aliases #118

jayqi opened this issue Apr 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jayqi
Copy link
Member

jayqi commented Apr 11, 2024

Python 3.12 introduced a new syntax "type statements" for declaring type aliases.

erdantic currently handles the old simple assignment syntax for type aliases, but not type statements.

Works

from typing import List

import erdantic as erd
from pydantic import BaseModel
import rich


class MyInnerModel(BaseModel):
    field: str

MyAlias = List[MyInnerModel]
print(type(MyAlias))
#> <class 'typing._GenericAlias'>

class MyOuterModel(BaseModel):
    aliased_field: MyAlias

diagram = erd.create(MyOuterModel)
rich.print(diagram)
#> EntityRelationshipDiagram(
#>     models={'__main__.MyInnerModel': ModelInfo(...), '__main__.MyOuterModel': ModelInfo(...)},
#>     edges={'__main__.MyOuterModel-aliased_field-__main__.MyInnerModel': Edge(...)}
#> )

Does not work

from typing import List

import erdantic as erd
from pydantic import BaseModel
import rich


class MyInnerModel(BaseModel):
    field: str

type MyAlias = List[MyInnerModel]
print(type(MyAlias))
#> <class 'typing.TypeAliasType'>

class MyOuterModel(BaseModel):
    aliased_field: MyAlias

diagram = erd.create(MyOuterModel)
rich.print(diagram)
#> EntityRelationshipDiagram(models={'__main__.MyOuterModel': ModelInfo(...)}, edges={})
@jayqi jayqi added the bug Something isn't working label Apr 11, 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

No branches or pull requests

1 participant