Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions python/temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ABSOLUTE_ZERO_C = -273.15


def celsius_to_fahrenheit(celsius):
if celsius < ABSOLUTE_ZERO_C:
raise ValueError("below absolute zero")
return celsius * 9 / 5 + 32
Comment on lines +5 to +7

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Severity

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.



def celsius_to_kelvin(celsius):
if celsius < ABSOLUTE_ZERO_C:
raise ValueError("below absolute zero")
return celsius - ABSOLUTE_ZERO_C