-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Better handling of unexpected types in SetPredicate
#11312
Better handling of unexpected types in SetPredicate
#11312
Conversation
`SetPredicate`: Emit warning and return `False` on unexpected value types
Thinking about this some more, I wonder if a warning is overkill and it would be better to just not match. If I remember correctly, it's somewhat difficult to filter this kind of warning that includes the values because I do think it's definitely overkill to add a separate method just for the warning here. |
Ah, good catch - That's an oversight from an older iteration of the implementation where the warning needed to be emitted at multiple locations. I can inline the call.
According to the docs, it seems like the But I too wonder if a warning is what we want, as this is something we should to enforce/implement consistently, i.e., emit the similar warnings about incompatible types in other predicates. |
The regular expression is used by |
Ah, I see. I'll just remove the warning then - seems like it's more trouble than it's worth. |
Check elements of sequence values for convertibility to `str` or `int`
Co-authored-by: Adriane Boyd <adrianeboyd@gmail.com>
* `Matcher`: Better type checking of values in `SetPredicate` `SetPredicate`: Emit warning and return `False` on unexpected value types * Rename `value_type_mismatch` variable * Inline warning * Remove unexpected type warning from `_SetPredicate` * Ensure that `str` values are not interpreted as sequences Check elements of sequence values for convertibility to `str` or `int` * Add more `INTERSECT` and `IN` test cases * Test for inputs with multiple characters * Return `False` early instead of using a boolean flag * Remove superfluous `int` check, parentheses * Apply suggestions from code review Co-authored-by: Adriane Boyd <adrianeboyd@gmail.com> * Appy suggestions from code review * Clarify test comment Co-authored-by: Adriane Boyd <adrianeboyd@gmail.com>
Description
The
IN
andNOT_IN
set predicates inMatcher
would raise an unhandled exception when matching against attribute values that are non-hashable (likelist
s). This is now resolved by performing some defensive type checking of the attribute values prior to calling the Pythonin
operator.Going forward, if any set predicate encounters a value of an unexpected type, it will fail early, i.e., return
False
, instead of crashing.Types of change
Bug fix.
Checklist