-
Notifications
You must be signed in to change notification settings - Fork 280
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
Applying logical OR to a constraint "fails" silently #4337
Comments
I've experimented a bit and I think I was wrong above - at least in what I meant. Using "and" or "or" will fail silently, but the thing that we'd be spotting to catch this is Constraint being cast to a bool. Using "&" works as expected and "|" fails with a TypeError. Given our docs don't say anything about "and" or "or" being ok, maybe it's just that one user thought that would be ok, rather than something that should be changed. |
The @SciTools/peloton have agreed that the This is not considered a breaking change since any code it breaks is using an anti-pattern. The docs are already clear on the correct use of |
After a little searching, I think raising
For reference, this is how numpy generates its familiar message Having said that, I think their use of ValueError instead of TypeError may be historical, and actually not quite right (except...
) |
✨ Feature Request
Whilst answering a recent support query, it was highlighted to me that currently applying logical OR to two constraints effectively fails silently.
Motivation
We could change Constraint to throw a NotImplementedError. Pros: people don't have a silent failure. Cons: currently functional code could start throwing exceptions.
Which should we do? Change it or leave it?
Additional context
The lack of an OR operator on them means that python falls back to its default behaviour of checking for truth in the first argument, returning it if it's "truthy", and if not returning the second argument
The text was updated successfully, but these errors were encountered: