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

[strawberry.ext.mypy_plugin] Fix import error for users who don't use pydantic #3018

Merged
merged 1 commit into from
Aug 8, 2023
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
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Release type: minor

Fix import error in `strawberry.ext.mypy_plugin` for users who don't use pydantic.
4 changes: 3 additions & 1 deletion strawberry/ext/mypy_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
)
from mypy.typevars import fill_typevars
from mypy.util import get_unique_redefinition_name
from strawberry.experimental.pydantic._compat import IS_PYDANTIC_V1

# Backwards compatible with the removal of `TypeVarDef` in mypy 0.920.
try:
Expand All @@ -64,8 +63,11 @@
try:
from pydantic.mypy import METADATA_KEY as PYDANTIC_METADATA_KEY
from pydantic.mypy import PydanticModelField

from strawberry.experimental.pydantic._compat import IS_PYDANTIC_V1
except ImportError:
PYDANTIC_METADATA_KEY = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also I think it is safe to add a default to false 😊

so

IS_PYDANTIC_V1 = False

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IS_PYDANTIC_V1 is used in if-else. Should I update it to if-elif and also set (and check in elif) IS_PYDANTIC_V2=False? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant only in the expect except ImportError: if we can't import pydantic it means we don't have it installed, so the default for IS_PYDANTIC_V1 doesn't matter that much :)

IS_PYDANTIC_V1 = False


if TYPE_CHECKING:
Expand Down
Loading