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 added for Python3.10's Union Pipe operator #102

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions src/attrs_strict/_type_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import inspect
import sys
import typing
import types
from collections.abc import Callable, Mapping, MutableMapping
from enum import Enum
from inspect import Parameter, Signature, signature
from itertools import zip_longest
from typing import ForwardRef

if sys.version_info >= (3, 8): # pragma: >=3.8 cover
from typing import Literal
else: # pragma: <3.8 cover
Expand Down Expand Up @@ -127,7 +127,7 @@ def _validate_elements(
raise _StringAnnotationError()
elif base_type == Literal or base_type == type(Literal): # type: ignore
_handle_literal(attribute, value, expected_type)
elif base_type == typing.Union: # type: ignore
elif base_type == typing.Union or base_type == types.UnionType: # type: ignore
_handle_union(attribute, value, expected_type)
elif not isinstance(value, base_type):
raise AttributeTypeError(value, attribute)
Expand Down Expand Up @@ -166,7 +166,7 @@ def _type_matching(

base_type = _get_base_type(expected)

if base_type == typing.Union: # type: ignore
if base_type == typing.Union or base_type == types.UnionType: # type: ignore
return any(
_type_matching(actual, expected_candidate)
for expected_candidate in expected.__args__
Expand Down
Loading