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

Fix error from type annotations containing ellipsis #127

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# erdantic Changelog

## v1.0.5 (Unreleased)

- Fixed runtime `AttributeError` that occurred when creating a diagram that includes a model with a field that uses a type annotation with ellipsis literal (e.g., `tuple[int, ...]`). ([Issue #124](https://github.com/drivendataorg/erdantic/issues/124), [PR #127](https://github.com/drivendataorg/erdantic/pull/127))

## v1.0.4 (2024-07-16)

- Fixed handling of `typing.Annotated` in cases where it's not the outermost generic type. ([Issue #122](https://github.com/drivendataorg/erdantic/issues/122), [PR #123](https://github.com/drivendataorg/erdantic/pull/123))
Expand Down
4 changes: 4 additions & 0 deletions erdantic/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ def _add_if_model(self, model: type, recurse: bool) -> bool:
# These are not going to be models
if "__qualname__" in str(e):
return False
# ellipsis object (used for example in tuple[int, ...]) don't have __module__ attribute
# This is also not going to be a model
elif "__module__" in str(e):
return False
raise
if key not in self.models:
try:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "erdantic"
version = "1.0.4"
version = "1.0.5"
description = "Entity relationship diagrams for Python data model classes like Pydantic."
readme = "README.md"
authors = [{ name = "DrivenData", email = "[email protected]" }, { name = "Jay Qi" }]
Expand Down
14 changes: 13 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from pathlib import Path
import sys
from typing import Any, AnyStr, List, Literal, Optional, TypeVar
from typing import Any, AnyStr, List, Literal, Optional, Tuple, TypeVar

if sys.version_info >= (3, 9):
from typing import Annotated
Expand Down Expand Up @@ -200,6 +200,18 @@ class MyModel(pydantic.BaseModel):

diagram = EntityRelationshipDiagram()
diagram.add_model(MyModel)
diagram.to_dot()


def test_model_with_ellipsis():
"""Model with Ellipsis should not error."""

class EllipsisModel(pydantic.BaseModel):
ellipsis_field: Tuple[int, ...]

diagram = EntityRelationshipDiagram()
diagram.add_model(EllipsisModel)
diagram.to_dot()


def test_model_with_no_fields():
Expand Down
Loading