You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
andlen(getattr(thing, "__args__", None) or []) ==0
):
returnst.from_type(origin)
As far as I've tested, Annotated[int, "foo"].__origin__ returns int, but len(Annotated[int, "foo"].__args__) is 1. I guess adding an extra condition here to check for the case of Annotated would fix the issue, but I'm not familiar with the codebase, so correct me if I'm wrong.
I found no workarounds for the issue, so any suggestions are highly appreciated!
The text was updated successfully, but these errors were encountered:
I think adding a clause for Annotated here would indeed fix your problem.
However, we might want to have a separate clause like if is_annotated_type(thing): just after is_typing_literal(), because we have both typing and typing_extensions, plus complications like type(typing_extensions.Annotated[int, "label"]) == typing_extensions._AnnotatedAlias which can probably vary with Python version.
(this would also make it easier for a future PR to support e.g. Annotated[float, lambda x: 0 <= x < 1], and resolve this to st.floats().filter(lambda x: 0 <= x < 1) with a plan (#2701) for st.floats(0, 1, exclude_max=True)... at least if we can convince people that this is the natural interpretation of callable predicates for annotated types)
Versions
Also tested with
python==3.9.0
and usingtyping.Annotated
instead oftyping_extensions.Annotated
.Problem description
hypothesis
is unable to generate data for a type ifAnnotated
is added. Example:The error that I receive is as follows:
I tried registering a strategy as the error message suggests like so:
... but the
my_strategy
function is never called, and the example fails with the same error.Potential solution
I followed the traceback to the function that failed and discovered this piece of code:
hypothesis/hypothesis-python/src/hypothesis/strategies/_internal/types.py
Lines 207 to 213 in ef0c174
As far as I've tested,
Annotated[int, "foo"].__origin__
returnsint
, butlen(Annotated[int, "foo"].__args__)
is1
. I guess adding an extra condition here to check for the case ofAnnotated
would fix the issue, but I'm not familiar with the codebase, so correct me if I'm wrong.I found no workarounds for the issue, so any suggestions are highly appreciated!
The text was updated successfully, but these errors were encountered: