chore(cint): explicitly handle NoneTypes

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang 2024-12-04 15:23:46 +05:30
parent 9c9349b74f
commit 1a45cd3ab0
No known key found for this signature in database
GPG key ID: 9DCC61E211BF645F

View file

@ -1066,8 +1066,7 @@ def flt(s: NumericType | str, precision: int | None = None) -> float: ...
@typing.overload
def flt(s: None) -> Literal[0.0]:
...
def flt(s: None) -> Literal[0.0]: ...
def flt(
@ -1113,7 +1112,7 @@ def flt(
return num
def cint(s: NumericType | str, default: int = 0) -> int:
def cint(s: NumericType | str | None, default: int = 0) -> int:
"""Convert to integer.
:param s: Number in string or other numeric format.
@ -1126,8 +1125,13 @@ def cint(s: NumericType | str, default: int = 0) -> int:
100
>>> cint("a")
0
>>> cint(None)
0
"""
if s is None:
return default
try:
return int(s)
except Exception: