remove dead try/except wrapper around mass * acceleration in newtons_second_law_of_motion#14884
Closed
HrachShah wants to merge 3 commits into
Closed
Conversation
added 3 commits
July 1, 2026 17:44
…second_law_of_motion — the function signature is annotated (mass: float, acceleration: float) -> float, and multiplying two float values cannot raise any exception on valid inputs. The previous 'try: force = mass * acceleration; except Exception: return -0.0' wrapper was dead code that silently masked TypeError when a caller violated the type contract (e.g. passing a string), KeyboardInterrupt, SystemExit, and any unrelated bug in this function body, by returning the unusual signed zero -0.0 which can poison downstream numerical code (-0.0 == 0.0 in equality checks but is distinct in repr and bit pattern). The plain expression makes the implementation match its type signature and its existing doctests; the two doctests still pass (100 and 2.0)
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.
The function is annotated
(mass: float, acceleration: float) -> floatand multiplying two floats cannot raise an exception on valid inputs.The previous wrapper:
was dead code that:
TypeErrorwhen a caller violated the type contract (e.g. passing a string)KeyboardInterruptandSystemExit-0.0, which can poison downstream numerical code (it equals0.0in equality checks but is distinct in repr and bit pattern)Replacing the wrapper with a plain
return mass * accelerationmakes the implementation match the function's annotated type signature and its existing doctests (newtons_second_law_of_motion(10, 10) == 100andnewtons_second_law_of_motion(2.0, 1) == 2.0).