Hello, following the example recipe given with the from_type() strategy (I removed the excluded_types: type | tuple[type] arg to simplify the code), I noticed that said recipe fails to type check:
# test.py
import typing
import hypothesis
import hypothesis.strategies as st
def everything_except() -> st.SearchStrategy[typing.Any]:
return (
st.from_type(type)
.flatmap(st.from_type)
.filter(lambda x: not isinstance(x, int))
)
fails with this error:
test.py:1139:50: error: Cannot use a covariant type variable as a parameter [misc]
A few observations:
- Note the line number — it’s always that line no matter where in the code I place this function.
- Placing a
# type: ignore[misc] comment doesn’t work for any line in the above test.
- Removing
flatmap() passes the type checks.
Running that strategy seems to work, though:
@hypothesis.given(data=everything_except())
def test_data(data: typing.Any) -> None:
print(type(data), data)
test_data()
produces the expected output.
This is for hypothesis v6.86.1 and mypy v1.5.1. Please let me know if you need more information, or if you’re able to reproduce.
I’m going to dig around some more later today to try and find the cause of the failing type check. For the time being, I’m going to (have to) decorate the function with @no_type_check to disable type checking.
Hello, following the example recipe given with the
from_type()strategy (I removed theexcluded_types: type | tuple[type]arg to simplify the code), I noticed that said recipe fails to type check:fails with this error:
A few observations:
# type: ignore[misc]comment doesn’t work for any line in the above test.flatmap()passes the type checks.Running that strategy seems to work, though:
produces the expected output.
This is for hypothesis v6.86.1 and mypy v1.5.1. Please let me know if you need more information, or if you’re able to reproduce.
I’m going to dig around some more later today to try and find the cause of the failing type check. For the time being, I’m going to (have to) decorate the function with
@no_type_checkto disable type checking.