Skip to content

Commit

Permalink
final CI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Nov 15, 2023
1 parent da3220c commit 99000b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
18 changes: 12 additions & 6 deletions hypothesis-python/src/hypothesis/strategies/_internal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,12 +1268,18 @@ def from_type_guarded(thing):

# Let registered extra modules handle their own recognized types first, before
# e.g. Unions are resolved
if thing not in types._global_type_lookup:
for module, resolver in types._global_extra_lookup.items():
if module in sys.modules:
strat = resolver(thing)
if strat is not None:
return strat
try:
known = thing in types._global_type_lookup
except TypeError:
# thing is not always hashable!
pass
else:
if not known:
for module, resolver in types._global_extra_lookup.items():
if module in sys.modules:
strat = resolver(thing)
if strat is not None:
return strat
if not isinstance(thing, type):
if types.is_a_new_type(thing):
# Check if we have an explicitly registered strategy for this thing,
Expand Down
15 changes: 6 additions & 9 deletions hypothesis-python/src/hypothesis/strategies/_internal/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def _get_constraints(args: Tuple[Any, ...]) -> Iterator["at.BaseMetadata"]:
yield arg
elif getattr(arg, "__is_annotated_types_grouped_metadata__", False):
yield from arg
elif isinstance(arg, slice) and arg.step == 1:
elif isinstance(arg, slice) and arg.step in (1, None):
yield from at.Len(arg.start or 0, arg.stop)


Expand All @@ -316,16 +316,13 @@ def find_annotated_strategy(annotated_type):
return arg

filter_conditions = []
if at := sys.modules.get("annotated_types"): # pragma: no branch
# `constraints` elements can be "consumed" by the next following calls/instructions
constraints = list(_get_constraints(metadata))

if "annotated_types" in sys.modules:
unsupported = []
for constraint in constraints:
if isinstance(constraint, (at.MultipleOf, at.Timezone)):
unsupported.append(constraint)
elif convert := get_constraints_filter_map().get(type(constraint)):
for constraint in _get_constraints(metadata):
if convert := get_constraints_filter_map().get(type(constraint)):
filter_conditions.append(convert(constraint))
else:
unsupported.append(constraint)
if unsupported:
msg = f"Ignoring unsupported {', '.join(map(repr, unsupported))}"
warnings.warn(msg, HypothesisWarning, stacklevel=2)
Expand Down

0 comments on commit 99000b8

Please sign in to comment.