-
Notifications
You must be signed in to change notification settings - Fork 586
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
Trying to resolve or register 'metadata' like typing.Annotated
should be an error
#2978
Comments
I have a question about this case with def my_factory(thing):
if isinstance(thing.__origin__, int):
return st.integers(**thing.__metadata__)
raise ...
st.register_type_strategy(Annotated, my_factory) So, this example can users help to write something like |
Just confirming, your only concern is registering bare Currently we 'see through' However I think that |
Sorry about from typing_extensions import Annotated
class HypothesisStrategyArgs(object):
def __init__(self, *args, **kwargs) -> None:
self.args = args
self.kwargs = kwargs
MyInt = Annotated[int, HypothesisStrategyArgs(min=1, max=3)]
def my_func(num: MyInt) -> int:
... It looks like an amazing API to me personally. |
It's going to be really, really hard to pass However... if we're accepting that, it would be easy to support |
Yes, I will create a PR soon! 👍 |
Some questions I got while working on this:
PositiveInt = Annotated[int, ...]
PositiveOddInt = Annotated[PositiveInt, ...] We can go into nested type or just ignore them. The other question is: it looks like
|
|
I can forbid using Does this sound right? 🤔 |
Yes 👍 I'd make |
Working on |
Should we allow to register it? Interesting question. I think that there might be cases when @Zac-HD do you agree? 🙂 |
There are definitely runtime uses, so I think we should allow it (and maybe even register it by default!). However, it's only valid if parametrized, so we should allow e.g. The trickier part is if we upgrade |
This was prompted by seeing PEP 655, which proposes a Required and NotRequired "type" analogous to typing.Annotated - that is, the correct way to resolve these types is to "see through" them to the actual type underneath.
(those might be added in 3.11; there's already implementations in typing_extensions and support from mypy)
However, from_type(typing.Annotated) or from_type(typing.Annotated) should be an explicit error - there's nothing wrapped that we could look at. For this issue, we should:
Python 3.10 will add more, including TypeGuard, Concatenate, TypeAlias, and maybe others.
The text was updated successfully, but these errors were encountered: