Skip to content

Commit

Permalink
Separate TypingUnionType and TypingGenericAlias import try-catch
Browse files Browse the repository at this point in the history
  • Loading branch information
tjeerddie committed Aug 9, 2023
1 parent 8375608 commit 5aa1804
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Release type: patch

Fix incorrect TypingUnionType import check of python version `< 3.9` to `< 3.10` in `experimental.pydantic.fields.py`
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
12 changes: 10 additions & 2 deletions strawberry/experimental/pydantic/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@

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

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

View check run for this annotation

Codecov / codecov/patch

strawberry/experimental/pydantic/fields.py#L25-L26

Added lines #L25 - L26 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

strawberry/experimental/pydantic/fields.py#L29

Added line #L29 was not covered by tests
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

# python < 3.10 does not have GenericAlias (list[int], tuple[str, ...] and so on)
# we do this under a conditional to avoid a mypy :)
if sys.version_info < (3, 10):
if sys.version_info < (3, 9):
TypingGenericAlias = ()
TypingUnionType = ()
else:
raise

Expand Down

0 comments on commit 5aa1804

Please sign in to comment.