-
-
Notifications
You must be signed in to change notification settings - Fork 24
Closed
Labels
Description
Python 3.10 introduced str | None
syntax which should be equivalent to Optional[str]
. At the moment such syntax isn't properly recognized by pure_protobuf
.
Following declaration will raise error:
@dataclass(kw_only=True)
class Bar(BaseMessage):
foo: Annotated[str | None, Field(1)]
with
UnsupportedAnnotationError: type annotation `str | None` is not supported
This is because get_origin
in pure_protobuf.helpers._typing.extract_optional
checks for Union
only, while this syntax has UnionType
from types
origin. The rest is the same.
This probably could be easily fixed by changing is
comparison to in (Union, UnionType)
, however special care must be taken, because (same as NoneType
) UnionType
was introduced in 3.10.
Thank you.
eigenein and drzbida