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

PEP 604 not supported - exception when writing union types X | Y #3255

Closed
MPalarya opened this issue Mar 12, 2022 · 1 comment · Fixed by #3279
Closed

PEP 604 not supported - exception when writing union types X | Y #3255

MPalarya opened this issue Mar 12, 2022 · 1 comment · Fixed by #3279
Labels
bug something is clearly wrong here interop how to play nicely with other packages

Comments

@MPalarya
Copy link

hypothesis is not recognizing the new bar-annotation for union types as a valid type on python 3.10+
resulting in an exception, see minimal reproduction example below -

from typing import Optional, Union
from dataclasses import dataclass

@dataclass
class A:
    x: str | None

@dataclass
class B:
    x: Union[str, None]

@dataclass
class C:
    x: Optional[str]

>>> st.from_type(A).example()
hypothesis.errors.InvalidArgument: thing=str | None must be a type

>>> st.from_type(B).example()
B(x='\U00076342\\\x8cî£\x00\x7f±b')

>>> st.from_type(C).example()
C(x='鏀\U00109e07h\x81ø\x9a\x9c\U0010a5e3\x8e=û')
@MPalarya MPalarya changed the title not support for PEP 604 - exception when writing union types X | Y PEP 604 not supported - exception when writing union types X | Y Mar 12, 2022
@Zac-HD Zac-HD added bug something is clearly wrong here interop how to play nicely with other packages labels Mar 14, 2022
@Zac-HD
Copy link
Member

Zac-HD commented Mar 14, 2022

Thanks for reporting this - #2979 has been open for nearly a year now, we definitely want it to work but nobody has yet volunteered to work on it.

(If you'd be interested in contributing, I'm happy to help out!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here interop how to play nicely with other packages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants