feat: add temperature conversion helpers - #69
Open
tsah-baz wants to merge 1 commit into
Open
Conversation
Comment on lines
+5
to
+7
| if celsius < ABSOLUTE_ZERO_C: | ||
| raise ValueError("below absolute zero") | ||
| return celsius * 9 / 5 + 32 |
There was a problem hiding this comment.
Non-finite temperatures bypass validation
celsius < ABSOLUTE_ZERO_C doesn't catch NaN or infinities, so celsius_to_fahrenheit and celsius_to_kelvin accept invalid inputs and propagate them through — should we validate finiteness explicitly in both functions?
Want Baz to fix this for you? Activate Fixer
Prompt for AI Agents
Before applying, verify this suggestion against the current code. In
python/temperature.py around lines 5-7 in `celsius_to_fahrenheit` and lines 10-13 in
`celsius_to_kelvin`, the current guard only checks `celsius < ABSOLUTE_ZERO_C`, which
does not reject NaN and lets infinities through (NaN makes the comparison false; ±inf
passes). Refactor both functions to explicitly validate that `celsius` is a finite real
number (e.g., reject `math.isnan` and `math.isinf`) before performing the absolute-zero
check and conversion. Ensure the same finiteness validation logic is applied
consistently to both entry points and raises ValueError when the input is not finite.
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.
Adds python temperature conversion helpers with absolute-zero validation.
Testing: exercised by hand.