Open mristin opened 1 year ago
Thank you for the bug report - I hope to get more!
This is a subtly difficult case. It's running afoul of some heuristics CrossHair uses to avoid reporting incorrect counterexamples when symbolics get passed to a module written in C that cannot tolerate them. Now that much of the standard library is patched, these heuristics are less important, but still play a role when using 3rd party libraries.
Looking over the symbolic integer implementation, it feels like I might be able to exclude it from the heuristic, though - catching the case your bring up here. I am going to investigate this soon and report back!
Eh, finally, one "guiding-principle" topic I've never said explicitly or put in the docs: CrossHair doesn't try very hard to catch the same kinds of issues that a static typechecker does. (e.g. mypy
already complains about min_sum = min(a_sum, min_sum)
in your example)
That said, CrossHair is a great compliment to mypy
; note that even after the fix for your example, mypy
complains about the return type of the function: it's Tuple[int, int]
, but the two return variables are typed as Optional[int]
. You can "fix" this by adding a line like assert min_sum is not None and max_sum is not None
- mypy will understand that the types are now non-None. But now you have to validate that the assert is accurate - and CrossHair is hopefully good at doing that part!
Anyway, as I said earlier - more to come.
Consider the following program (a solution to https://www.hackerrank.com/challenges/mini-max-sum/problem):
CrossHair 0.0.34 fails to figure out that putting a
None
inmin
ormax
is going to crash the program. The doctest fails with an exception, as expected.The correct program looks like this (mind the lines
min_sum = ...
andmax_sum = ...
):I ran CrossHair 0.0.34 with:
Letting CrossHair in watch mode run longer did not help either: