File tree Expand file tree Collapse file tree 3 files changed +14
-0
lines changed
src/hypothesis/strategies/_internal Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change
1
+ RELEASE_TYPE: patch
2
+
3
+ Fix :func: `~hypothesis.strategies.from_type `
4
+ on :class: `collections.abc.Callable ` returning :const: `None `.
Original file line number Diff line number Diff line change @@ -1031,6 +1031,9 @@ def resolve_Callable(thing):
1031
1031
"Consider using an explicit strategy, or opening an issue."
1032
1032
)
1033
1033
1034
+ if get_origin (thing ) is collections .abc .Callable and return_type is None :
1035
+ return_type = type (None )
1036
+
1034
1037
return st .functions (
1035
1038
like = (lambda * a , ** k : None ) if args_types else (lambda : None ),
1036
1039
returns = st .from_type (return_type ),
Original file line number Diff line number Diff line change 8
8
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
9
9
# obtain one at https://mozilla.org/MPL/2.0/.
10
10
11
+ import collections .abc
11
12
import dataclasses
12
13
import sys
13
14
import typing
@@ -174,3 +175,9 @@ def __iter__(self):
174
175
@given (...)
175
176
def test_grouped_protocol_strategy (x : typing .Annotated [int , LazyStrategyAnnotation ()]):
176
177
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 )
You can’t perform that action at this time.
0 commit comments