Skip to content

Commit 6f1baec

Browse files
committed
fix from_type(type) regression
1 parent f011f1a commit 6f1baec

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

hypothesis-python/RELEASE.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RELEASE_TYPE: patch
2+
3+
This patch restores diversity to the outputs of
4+
:func:`from_type(type) <hypothesis.strategies.from_type>` (:issue:`4144`).

hypothesis-python/src/hypothesis/strategies/_internal/types.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,7 @@ def really_inner(thing):
822822
@register("Type")
823823
@register("Type", module=typing_extensions)
824824
def resolve_Type(thing):
825-
if getattr(thing, "__args__", None) is None:
826-
return st.just(type)
827-
elif get_args(thing) == (): # pragma: no cover
825+
if getattr(thing, "__args__", None) is None or get_args(thing) == ():
828826
return _fallback_type_strategy
829827
args = (thing.__args__[0],)
830828
if is_a_union(args[0]):

hypothesis-python/tests/nocover/test_from_type_recipe.py

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from hypothesis import given, strategies as st
1212
from hypothesis.strategies._internal.types import _global_type_lookup
1313

14+
from tests.common.debug import find_any
15+
1416
TYPES = sorted(
1517
(
1618
x
@@ -39,3 +41,7 @@ def everything_except(excluded_types):
3941
def test_recipe_for_everything_except(excluded_types, data):
4042
value = data.draw(everything_except(excluded_types))
4143
assert not isinstance(value, excluded_types)
44+
45+
46+
def test_issue_4144_regression():
47+
find_any(everything_except(()), lambda t: t is not type)

0 commit comments

Comments
 (0)