Skip to content

fix: validate binary_and inputs - #15277

Merged
cclauss merged 1 commit into
TheAlgorithms:masterfrom
nishanty23:patch-1
Sep 13, 2026
Merged

fix: validate binary_and inputs#15277
cclauss merged 1 commit into
TheAlgorithms:masterfrom
nishanty23:patch-1

Conversation

@nishanty23

Copy link
Copy Markdown
Contributor

Description

This PR improves input validation in binary_and().

Changes

  • Raise TypeError when either input is not an integer.
  • Correct the negative-input error message from "positive" to "non-negative".
  • Update doctests to verify the new validation behavior.
  • Add a doctest covering an invalid second argument.

Testing

  • python -m doctest -v bit_manipulation/binary_and_operator.py
  • ruff check bit_manipulation/binary_and_operator.py

@cclauss

cclauss commented Sep 12, 2026

Copy link
Copy Markdown
Member

ON HOLD: Our focus is on merging or closing old pull requests before October 1st.

@priya-sundaram-dev priya-sundaram-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cclauss

cclauss commented Sep 13, 2026

Copy link
Copy Markdown
Member

Please add that doctest.

@cclauss cclauss added the awaiting changes A maintainer has requested changes to this PR label Sep 13, 2026
@cclauss
cclauss merged commit 2b6f77b into TheAlgorithms:master Sep 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes A maintainer has requested changes to this PR on hold

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants