From 08e1f45025e56b3ba7978a32166ec269afbb5149 Mon Sep 17 00:00:00 2001 From: advik Date: Tue, 6 Feb 2024 00:56:04 +0530 Subject: [PATCH] Fixes empty string bug in str isalpha method --- integration_tests/test_str_01.py | 3 +++ lpython | 1 + src/runtime/lpython_builtin.py | 1 + 3 files changed, 5 insertions(+) create mode 160000 lpython diff --git a/integration_tests/test_str_01.py b/integration_tests/test_str_01.py index 513279c9b2..be31827fac 100644 --- a/integration_tests/test_str_01.py +++ b/integration_tests/test_str_01.py @@ -42,14 +42,17 @@ def test_str_isalpha(): b: str = "hj kl" c: str = "a12(){}A" d: str = " " + e: str = "" res: bool = a.isalpha() res2: bool = b.isalpha() res3: bool = c.isalpha() res4: bool = d.isalpha() + res5: bool = e.isalpha() assert res == True assert res2 == False assert res3 == False assert res4 == False + assert res5 == False def test_str_title(): diff --git a/lpython b/lpython new file mode 160000 index 0000000000..467081ec8c --- /dev/null +++ b/lpython @@ -0,0 +1 @@ +Subproject commit 467081ec8c95ae7a5008062ae98207625c2f4511 diff --git a/src/runtime/lpython_builtin.py b/src/runtime/lpython_builtin.py index a0126da791..1ac93fbfa9 100644 --- a/src/runtime/lpython_builtin.py +++ b/src/runtime/lpython_builtin.py @@ -687,6 +687,7 @@ def _lpython_str_join(s:str, lis:list[str]) -> str: def _lpython_str_isalpha(s: str) -> bool: ch: str + if len(s) == 0: return False for ch in s: ch_ord: i32 = ord(ch) if 65 <= ch_ord and ch_ord <= 90: