Skip to content

Commit

Permalink
In st.from_type(), handle typing.Unpack like annotated_types.GroupedM…
Browse files Browse the repository at this point in the history
…etadata
  • Loading branch information
dvir478 committed May 18, 2024
1 parent 26ea571 commit 56006d8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions hypothesis-python/src/hypothesis/strategies/_internal/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,24 @@ def get_constraints_filter_map():

def _get_constraints(args: Tuple[Any, ...]) -> Iterator["at.BaseMetadata"]:
at = sys.modules.get("annotated_types")
unpack = getattr (typing, "Unpack",object() )
for arg in args:
if at and isinstance(arg, at.BaseMetadata):
yield arg
elif getattr(arg, "__is_annotated_types_grouped_metadata__", False):
elif get_origin (arg) is unpack:
for subarg in arg:
if getattr(subarg, "__is_annotated_types_grouped_metadata__", False):
yield from _get_constraints(tuple(subarg))
else:
yield subarg


elif getattr(arg, "__is_annotated_types_grouped_metadata__", False):
for subarg in arg:
if getattr(subarg, "__is_annotated_types_grouped_metadata__", False):
yield from _get_constraints(tuple(subarg))
elif get_origin(arg) is unpack:
yield from _get_constraints(get_args(subarg))
else:
yield subarg
elif at and isinstance(arg, slice) and arg.step in (1, None):
yield from at.Len(arg.start or 0, arg.stop)

Expand Down

0 comments on commit 56006d8

Please sign in to comment.