New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to recompute the values of the contract condition #229
Comments
Hi @leshchenko1979 , |
Absolutely no worries, thanks. I'll also try the |
Just been looking at this. The error seems to be quite widespread in my (attempted) use-case. Here's a minimal, reproducible example: from icontract import require
from numpy import arange
@require(lambda x: len(x) >= 10)
def identity(x):
return x
identity(arange(5)) with
|
I'm trying to isolate this even further: from icontract import require, ViolationError
from numpy import arange
@require(lambda x: len(x) >= 10)
def identity(x):
return x
for x in [
[0, 1, 2, 3, 4],
(0, 1, 2, 3, 4),
range(5),
arange(5),
arange(10),
]:
print("Trying", x)
try:
identity (x)
print("Passes")
except (ViolationError, RuntimeError) as e:
print(type(e))
print() Output:
It seems like the bug happens when there is an invalid condition based on a numpy array (as it also was with my original case above). PS. @dycw You have a peculiar yet very informative traceback structure. Where does it come from? |
Hi @leshchenko1979 I use https://github.com/Qix-/better-exceptions It appears we've both run into this problem as we're in the |
The numpy arrays do not like `PLACEHOLDER in arr` which will cause a `ValueError`. However, we tested for `PLACEHOLDER` everywhere using `in` operator in the representation module. This patch fixes the problem by using explicit `any(...)` and checking also explicitly for `... is PLACEHOLDER`. In contrast, `in` operator uses equality (`==`) instead of identity (`is`), which was not the desirable behavior anyhow originally. Fixes #229.
Hi @dycw and @leshchenko1979 , Could you please double-check that the pull request #232 fixes the issue on your machine as well before I merge it in? |
The numpy arrays do not like `PLACEHOLDER in arr` which will cause a `ValueError`. However, we tested for `PLACEHOLDER` everywhere using `in` operator in the representation module. This patch fixes the problem by using explicit `any(...)` and checking also explicitly for `... is PLACEHOLDER`. In contrast, `in` operator uses equality (`==`) instead of identity (`is`), which was not the desirable behavior anyhow originally. Fixes #229.
Yep, works fine for me, thanks! |
The numpy arrays do not like `PLACEHOLDER in arr` which will cause a `ValueError`. However, we tested for `PLACEHOLDER` everywhere using `in` operator in the representation module. This patch fixes the problem by using explicit `any(...)` and checking also explicitly for `... is PLACEHOLDER`. In contrast, `in` operator uses equality (`==`) instead of identity (`is`), which was not the desirable behavior anyhow originally. Fixes #229.
Thanks again for the bug report, @leshchenko1979 and @dycw! I've just released v2.5.5 which should be available on PyPI shortly. Please let me know if there are more issues. (Btw., could you please star the project on GitHub if you haven't done so already to give it some visibility?) |
Of course, already did! Thanks for the fix! |
I have the following code:
If the first contract fails, I'm getting a RuntimeError instead of a ViolationError:
I also made the second one fail with
pytest
, and the test output was:The text was updated successfully, but these errors were encountered: