chore(flt): explicitly handle NoneTypes
These were implicitly handled due to the catch-all 0.0 return, but type checkers break here, and a lot of places depend on this behaviour Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
2fda32887c
commit
cfeb1224e6
1 changed files with 14 additions and 1 deletions
|
|
@ -1078,7 +1078,14 @@ def flt(s: NumericType | str, precision: int | None = None) -> float:
|
|||
...
|
||||
|
||||
|
||||
def flt(s: NumericType | str, precision: int | None = None, rounding_method: str | None = None) -> float:
|
||||
@typing.overload
|
||||
def flt(s: None) -> Literal[0.0]:
|
||||
...
|
||||
|
||||
|
||||
def flt(
|
||||
s: NumericType | str | None, precision: int | None = None, rounding_method: str | None = None
|
||||
) -> float:
|
||||
"""Convert to float (ignoring commas in string).
|
||||
|
||||
:param s: Number in string or other numeric format.
|
||||
|
|
@ -1097,7 +1104,13 @@ def flt(s: NumericType | str, precision: int | None = None, rounding_method: str
|
|||
10500.57
|
||||
>>> flt("a")
|
||||
0.0
|
||||
>>> flt(None)
|
||||
0.0
|
||||
"""
|
||||
|
||||
if s is None:
|
||||
return 0.0
|
||||
|
||||
if isinstance(s, str):
|
||||
s = s.replace(",", "")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue