Merge pull request #28661 from akhilnarang/cint-explicit-handle-nonetype

chore(cint): explicitly handle NoneTypes
This commit is contained in:
Akhil Narang 2024-12-04 15:51:13 +05:30 committed by GitHub
commit 1b8ee6917c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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: