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

Closed
davetapley opened this issue Nov 13, 2024 · 2 comments · Fixed by #622
Closed

Support PEP 695 type statements #611

davetapley opened this issue Nov 13, 2024 · 2 comments · Fixed by #622
Assignees
Labels
enhancement New feature or request

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
@yukinarit yukinarit added the enhancement New feature or request label Nov 17, 2024
@yukinarit yukinarit changed the title Support type statements Support PEP 695 type statements Nov 17, 2024
@yukinarit yukinarit self-assigned this Nov 17, 2024
yukinarit added a commit that referenced this issue Dec 17, 2024
yukinarit added a commit that referenced this issue Dec 17, 2024
yukinarit added a commit that referenced this issue Dec 18, 2024
yukinarit added a commit that referenced this issue Dec 18, 2024
@yukinarit
Copy link
Owner

Hi @davetapley!
I made a PR #622. Can you check to see if it works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants