fix: validate binary_and inputs - #15277
Conversation
|
ON HOLD: Our focus is on merging or closing old pull requests before October 1st. |
priya-sundaram-dev
left a comment
There was a problem hiding this comment.
Nice cleanup — this turns the previous confusing failures (Unknown format code 'b' for object of type 'float', and the str-vs-int comparison error) into clear, intentional TypeErrors, and "non-negative" is the accurate wording since 0 is allowed by the a < 0 check. I ran the doctests and they pass.
One thing worth a conscious decision (not a blocker): type(a) is not int deliberately rejects bool, since bool is a subclass of int. So binary_and(True, False) now raises TypeError rather than treating them as 1/0. That's defensible (booleans aren't really the intended input here), but if you'd rather accept them you'd use isinstance(a, int). Whichever you choose, a one-line doctest pinning the bool behavior would make the intent explicit.
Otherwise this LGTM. Approving.
|
Please add that doctest. |
Description
This PR improves input validation in
binary_and().Changes
TypeErrorwhen either input is not an integer.Testing
python -m doctest -v bit_manipulation/binary_and_operator.pyruff check bit_manipulation/binary_and_operator.py