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 type statements #611

Open
davetapley opened this issue Nov 13, 2024 · 1 comment
Open

Support type statements #611

davetapley opened this issue Nov 13, 2024 · 1 comment

Comments

@davetapley
Copy link
Contributor

davetapley commented Nov 13, 2024

Repro (requires Python >3.12):

from dataclasses import dataclass

from serde.yaml import to_yaml


@dataclass
class Foo:
    a: int


@dataclass
class Bar:
    b: int


@dataclass
class ContainerUnion:
    data: Foo | Bar


c = ContainerUnion(Foo(1))

print(to_yaml(c))  # ok

type FooBar = Foo | Bar


@dataclass
class ContainerType:
    data: FooBar


c = ContainerType(Foo(1))

print(to_yaml(c))
# serde.compat.SerdeError: Unsupported type: Foo

https://typing.readthedocs.io/en/latest/spec/aliases.html#type-statement

@davetapley
Copy link
Contributor Author

Not that if you remove type (i.e. FooBar = Foo | Bar), then it works.

So that's a good enough workaround for now, for me, since I don't need generics.

@davetapley davetapley changed the title Support PEP 613 Support type statements Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant