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 incorrect TypingUnionType import check #3023

Merged
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
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Release type: patch

TypingUnionType import error check is reraised because TypingGenericAlias is checked at the same time which is checked under 3.9 instead of under 3.10

Fix by separating TypingUnionType and TypingGenericAlias imports in their own try-catch
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def tests_integrations(session: Session, integration: str) -> None:
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", integration)


@session(python=["3.11"], name="Pydantic tests", tags=["tests"])
@session(python=PYTHON_VERSIONS, name="Pydantic tests", tags=["tests"])
@nox.parametrize("pydantic", ["1.10", "2.0.3"])
def test_pydantic(session: Session, pydantic: str) -> None:
session.run_always("poetry", "install", external=True)
Expand Down
13 changes: 9 additions & 4 deletions strawberry/experimental/pydantic/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@

try:
from types import UnionType as TypingUnionType
except ImportError:
import sys

if sys.version_info < (3, 10):
TypingUnionType = ()
else:
raise

Check warning on line 31 in strawberry/experimental/pydantic/fields.py

View check run for this annotation

Codecov / codecov/patch

strawberry/experimental/pydantic/fields.py#L31

Added line #L31 was not covered by tests

try:
from typing import GenericAlias as TypingGenericAlias # type: ignore
except ImportError:
import sys
Expand All @@ -32,10 +41,6 @@
TypingGenericAlias = ()
tjeerddie marked this conversation as resolved.
Show resolved Hide resolved
else:
raise
if sys.version_info < (3, 10):
TypingUnionType = ()
else:
raise

ATTR_TO_TYPE_MAP = {
"NoneStr": Optional[str],
Expand Down
Loading