Skip to content

Commit 1560b22

Browse files
committed
Fix from_type failure on collections.abc.Callable[..., None]
1 parent fa0d158 commit 1560b22

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RELEASE_TYPE: patch
2+
3+
Fix :func:`~hypothesis.strategies.from_type`
4+
on :class:`collections.abc.Callable` returning :const:`None`.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,9 @@ def resolve_Callable(thing):
10311031
"Consider using an explicit strategy, or opening an issue."
10321032
)
10331033

1034+
if get_origin(thing) is collections.abc.Callable and return_type is None:
1035+
return_type = type(None)
1036+
10341037
return st.functions(
10351038
like=(lambda *a, **k: None) if args_types else (lambda: None),
10361039
returns=st.from_type(return_type),

hypothesis-python/tests/cover/test_lookup_py39.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
99
# obtain one at https://mozilla.org/MPL/2.0/.
1010

11+
import collections.abc
1112
import dataclasses
1213
import sys
1314
import typing
@@ -174,3 +175,9 @@ def __iter__(self):
174175
@given(...)
175176
def test_grouped_protocol_strategy(x: typing.Annotated[int, LazyStrategyAnnotation()]):
176177
assert x is sentinel
178+
179+
180+
def test_collections_abc_callable_none():
181+
# https://github.com/HypothesisWorks/hypothesis/issues/4192
182+
s = st.from_type(collections.abc.Callable[[None], None])
183+
assert_all_examples(s, lambda x: callable(x) and x(None) is None)

0 commit comments

Comments
 (0)