3 ms·
I'm wondering about whether using exceptions in the utility functions is misusing Python's exception handling system... Look at is_integer() for example. Is ca
by peatfreak 4y ago
I'm wondering about whether using exceptions in the utility functions is misusing Python's exception handling system... Look at is_integer() for example. Is catching ValueError -- if the token cannot be converted -- a Pythonic thing? Or is it abusing exceptions for ordinary (non-exceptional) tokenizing?
- rollcat 4y agoLooking at the usage of is_integer, personally I would write something like parse_integer(x: str) -> Optional[int], where the None variant represents a caught ValueError; this avoids parsing the integer twice but achieves basically the same effect (in a very similar style). What would you propose as "more pythonic" here? Writing your own integer parsing code, by looking at the ASCII values of each character in the string?
- dragonwriter 4y agoIt's suboptimal and you wouldn't want it for a production interpreter, but it's the lowest friction for leveraging what you get for free with Python to get something working correctly.