maths/largest_of_very_large_numbers: validate positive input as docstring documents#14933
Open
thejesh23 wants to merge 1 commit into
Open
maths/largest_of_very_large_numbers: validate positive input as docstring documents#14933thejesh23 wants to merge 1 commit into
thejesh23 wants to merge 1 commit into
Conversation
The docstring already documents that res(-1, 5) should raise `ValueError: expected a positive input`, but no such validation exists. Calling res() with a negative x currently reaches `math.log10(x)` and raises `ValueError: math domain error` instead, so the documented doctest fails. Add the missing check at the top of the function so it matches the documented contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
Fixes #14930
The docstring of
res()inmaths/largest_of_very_large_numbers.pyalready documents:```
but the corresponding check was never actually written. Calling
res(-1, 5)reachesmath.log10(-1)and raisesValueError: math domain errorinstead of the documented message, so the doctest fails underpython -m doctest maths/largest_of_very_large_numbers.pyon current master.This PR adds the missing two-line guard so the code matches its documented contract:
```python
if x < 0:
raise ValueError("expected a positive input")
```
After the change, all four doctests in the file pass. The doctest itself was not changed — it already described the intended behaviour.
Checklist: