Python
09 Sep 2026
9 min read
Accept Numeric Protocols with Fraction.from_number
A function that accepts a number and a function that parses text are not quite the same API. I keep running into this distinction in configuration code, pricing tools, import pipelines, and small libraries. The caller may already have an int, float, Decimal, or another numeric object. In that case, accepting a string such as "0.25" just because it happens to look numeric can make the boundary less clear than it needs to be.