reject bool and float as polygon sides; cover negative-breadth cuboid#14790
Closed
HrachShah wants to merge 14 commits into
Closed
reject bool and float as polygon sides; cover negative-breadth cuboid#14790HrachShah wants to merge 14 commits into
HrachShah wants to merge 14 commits into
Conversation
added 14 commits
April 20, 2026 21:35
…ix Python 3 multi-exception syntax in instagram_crawler
…xception — int() raises ValueError on non-numeric input, not a generic Exception
…emoved in Python 3, use parentheses instead
…oat*float can only raise TypeError for incompatible types; the bare Exception was masking real bugs from the caller
The bare 'except Exception' around mass * acceleration was catching RecursionError, MemoryError, KeyboardInterrupt, and any unrelated bug in surrounding code. The multiplication of two Python objects can only raise TypeError (wrong operand types) or OverflowError (very large floats), so narrowing to TypeError matches the documented error path and lets other exceptions propagate as designed. Also adds a doctest that exercises the error path with a None argument, so the new behavior is locked in by the test suite.
Two real bugs in maths/area.py: 1. area_reg_polygon()'s isinstance(sides, int) check was passing for bool, because bool is a subclass of int in Python. area_reg_polygon(True, 5) would silently compute cot(pi/1) for a '1-sided regular polygon' and return a real number, when the function is meant to reject anything that is not a genuine integer count of sides >= 3. Added an explicit isinstance(sides, bool) check and a docstring note explaining the subclass relationship. Also split the original so the type check on sides and the non-negative check on length are no longer mutually exclusive branches. Previously, sides=True and length=-1 would silently pass the type guard, then hit the elif and raise the wrong error. Added doctest cases for area_reg_polygon(True, 5) and area_reg_polygon(3.0, 5) so the new behavior is locked in. 2. surface_area_cuboid()'s existing test coverage happened to miss triples where the negative argument is the *middle* one (length=1, breadth=-1, height=1). Added a doctest case for that exact input. The if-statement itself was already correct (short- circuit-or with three comparands binds tighter than the not-yet-existing precedence issue), but the missing test meant nothing was actually exercising the breadth < 0 branch in isolation. The new case locks it in. Verified: `python3 -m doctest maths/area.py -v` reports '116 passed and 0 failed'.
Closing this pull request as invalid@HrachShah, this pull request is being closed as none of the checkboxes have been marked. It is important that you go through the checklist and mark the ones relevant to this pull request. Please read the Contributing guidelines. If you're facing any problem on how to mark a checkbox, please read the following instructions:
NOTE: Only |
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.
Two real bugs in maths/area.py:
Also split the original if ... elif ... so the type check on sides and the non-negative check on length are no longer mutually exclusive branches.
Added doctest cases for area_reg_polygon(True, 5) and area_reg_polygon(3.0, 5) so the new behavior is locked in.
Verified: python3 -m doctest maths/area.py -v reports '116 passed and 0 failed'.