Skip to content

remove dead try/except wrapper around mass * acceleration in newtons_second_law_of_motion#14884

Closed
HrachShah wants to merge 3 commits into
TheAlgorithms:masterfrom
HrachShah:fix/newtons-second-law-remove-dead-try-except
Closed

remove dead try/except wrapper around mass * acceleration in newtons_second_law_of_motion#14884
HrachShah wants to merge 3 commits into
TheAlgorithms:masterfrom
HrachShah:fix/newtons-second-law-remove-dead-try-except

Conversation

@HrachShah

Copy link
Copy Markdown

The function is annotated (mass: float, acceleration: float) -> float and multiplying two floats cannot raise an exception on valid inputs.

The previous wrapper:

force = 0.0
try:
    force = mass * acceleration
except Exception:
    return -0.0
return force

was dead code that:

  • silently masked TypeError when a caller violated the type contract (e.g. passing a string)
  • silently swallowed KeyboardInterrupt and SystemExit
  • returned the unusual signed zero -0.0, which can poison downstream numerical code (it equals 0.0 in equality checks but is distinct in repr and bit pattern)

Replacing the wrapper with a plain return mass * acceleration makes the implementation match the function's annotated type signature and its existing doctests (newtons_second_law_of_motion(10, 10) == 100 and newtons_second_law_of_motion(2.0, 1) == 2.0).

Zo Bot 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)
@HrachShah HrachShah requested a review from cclauss as a code owner July 1, 2026 17:45
@algorithms-keeper

Copy link
Copy Markdown

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:

  • Read a point one at a time and think if it is relevant to the pull request or not.
  • If it is, then mark it by putting a x between the square bracket like so: [x]

NOTE: Only [x] is supported so if you have put any other letter or symbol between the brackets, that will be marked as invalid. If that is the case then please open a new pull request with the appropriate changes.

@algorithms-keeper algorithms-keeper Bot closed this Jul 1, 2026
@algorithms-keeper algorithms-keeper Bot removed the request for review from cclauss July 1, 2026 17:46
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed invalid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant