File tree 3 files changed +24
-1
lines changed
src/hypothesis/strategies/_internal
3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change
1
+ RELEASE_TYPE: patch
2
+
3
+ This patch fixes a bug where :func: `~hypothesis.strategies.from_type ` would error on certain types involving :class: `~python:typing.Protocol ` (:issue: `4194 `).
Original file line number Diff line number Diff line change @@ -541,7 +541,9 @@ def from_typing_type(thing):
541
541
else :
542
542
union_elems = ()
543
543
if not any (
544
- isinstance (T , type ) and issubclass (int , get_origin (T ) or T )
544
+ # see https://github.com/HypothesisWorks/hypothesis/issues/4194 for
545
+ # try_issubclass.
546
+ isinstance (T , type ) and try_issubclass (int , get_origin (T ) or T )
545
547
for T in [* union_elems , elem_type ]
546
548
):
547
549
mapping .pop (bytes , None )
Original file line number Diff line number Diff line change @@ -1237,3 +1237,21 @@ def test_from_type_resolves_required_posonly_args(n: CustomInteger):
1237
1237
# st.builds() does not infer for positional arguments, but st.from_type()
1238
1238
# does. See e.g. https://stackoverflow.com/q/79199376/ for motivation.
1239
1239
assert isinstance (n , CustomInteger )
1240
+
1241
+
1242
+ class MyProtocol (typing .Protocol ):
1243
+ pass
1244
+
1245
+
1246
+ def test_issue_4194_regression ():
1247
+ # this was an edge case where we were calling issubclass on something
1248
+ # that was not a type, which errored. I don't have a more principled test
1249
+ # case or name for this.
1250
+ inner = typing .Union [typing .Sequence ["A" ], MyProtocol ]
1251
+ A = typing .Union [typing .Sequence [inner ], MyProtocol ]
1252
+
1253
+ with (
1254
+ temp_registered (MyProtocol , st .just (b"" )),
1255
+ temp_registered (typing .ForwardRef ("A" ), st .integers ()),
1256
+ ):
1257
+ find_any (st .from_type (A ))
You can’t perform that action at this time.
0 commit comments