From 1a45cd3ab00d08deb16b5bf0719c33e6088cd89c Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Wed, 4 Dec 2024 15:23:46 +0530 Subject: [PATCH] chore(cint): explicitly handle NoneTypes Signed-off-by: Akhil Narang --- frappe/utils/data.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frappe/utils/data.py b/frappe/utils/data.py index fe9ddfc4c8..c83f9bbc1b 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -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: