Skip to content
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

update BasicCriterion.__bool__ to prevent chained comparisons #712

Open
thinkingatoms opened this issue Nov 23, 2022 · 0 comments
Open

update BasicCriterion.__bool__ to prevent chained comparisons #712

thinkingatoms opened this issue Nov 23, 2022 · 0 comments

Comments

@thinkingatoms
Copy link

thinkingatoms commented Nov 23, 2022

I know it's really not the intended usage, but one could write an expression like 0 <= Field("abc") < 10, which would result in a Criterion that looks like BasicCriterion(Equality.lt, Field("abc"), 10).

This is not surprising because python breaks down the chained comparison as separate comparisons joined by the python and, whose behavior cannot be overridden. This is dangerous because the statement is valid but the resulting criterion does not match what the code intended.

I know updating (Basic)Criterion.__bool__ to throw is probably not the right solution here, but it would be nice if there was some way to detect/prevent against this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant