Skip to content

Commit 20b93b4

Browse files
authored
Merge pull request #2484 from advikkabra/isalpha-fix
Fixes empty string bug in str isalpha method
2 parents a6b9256 + 08e1f45 commit 20b93b4

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

integration_tests/test_str_01.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ def test_str_isalpha():
4242
b: str = "hj kl"
4343
c: str = "a12(){}A"
4444
d: str = " "
45+
e: str = ""
4546
res: bool = a.isalpha()
4647
res2: bool = b.isalpha()
4748
res3: bool = c.isalpha()
4849
res4: bool = d.isalpha()
50+
res5: bool = e.isalpha()
4951
assert res == True
5052
assert res2 == False
5153
assert res3 == False
5254
assert res4 == False
55+
assert res5 == False
5356

5457

5558
def test_str_title():

lpython

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 467081ec8c95ae7a5008062ae98207625c2f4511

src/runtime/lpython_builtin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ def _lpython_str_join(s:str, lis:list[str]) -> str:
687687

688688
def _lpython_str_isalpha(s: str) -> bool:
689689
ch: str
690+
if len(s) == 0: return False
690691
for ch in s:
691692
ch_ord: i32 = ord(ch)
692693
if 65 <= ch_ord and ch_ord <= 90:

0 commit comments

Comments
 (0)