fix: enhance numeric parsing to support scientific notation and ambiguous hex#13
Conversation
|
The happy path is fixed — What the current PR branch doesI ran each of these against
The first block (malformed scientific notation + Worse, these propagate into the public API: compare_numbers(["1e", "<", "31"]) # returns "true" (should raise)
math_operation(["e10", "+", "1"]) # returns "3601" (should raise)
compare_numbers(["NaN", "<", "10"]) # raises decimal.InvalidOperation (should raise ValueError)
math_operation(["Infinity", "+", "1"]) # raises OverflowError from _num_to_str (should raise ValueError)What I'd like to see before merging
@pytest.mark.parametrize("raw", [
"1e", "e10", "1E", "E10", "1e1e",
"0b10", "0B10",
"NaN", "nan", "Infinity", "-Infinity", "sNaN",
"_10", "1__0", "1_",
])
def test_parse_numeric_exact_rejects_malformed(raw):
with pytest.raises(ValueError):
calc._parse_numeric_exact(raw)
How you get there is up to you — there are a few ways to structure the checks. Happy to re-review once the negative suite is green. |
|
Addressed the negative path cases and added the suggested test suite ready for re-review @rawBit-io |
Description
This PR fixes #10:
_parse_numeric_exactcorrectly parses scientific notation (e.g.,"1e6","1e8") as decimal values, not as hexadecimal.math_operationandcompare_numbersfor such inputs.Checklist
Closes #10