Skip to content

Commit 368fe72

Browse files
committed
Fix underscores for isupper
1 parent 914299a commit 368fe72

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

tests/snippets/strings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,6 @@ def try_mutate_str():
324324
assert not "a".__ne__("a")
325325
assert not "".__ne__("")
326326
assert "".__ne__(1) == NotImplemented
327+
328+
assert "A_B".isupper()
329+
assert "a_b".islower()

vm/src/obj/objstr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,11 +727,12 @@ impl PyString {
727727

728728
#[pymethod]
729729
fn isupper(&self, _vm: &VirtualMachine) -> bool {
730+
// TODO: assert not " ".isupper(), assert not "_".isupper()
730731
!self.value.is_empty()
731732
&& self
732733
.value
733734
.chars()
734-
.filter(|x| !x.is_ascii_whitespace())
735+
.filter(|x| !x.is_ascii_whitespace() && *x != '_')
735736
.all(char::is_uppercase)
736737
}
737738

@@ -741,7 +742,7 @@ impl PyString {
741742
&& self
742743
.value
743744
.chars()
744-
.filter(|x| !x.is_ascii_whitespace())
745+
.filter(|x| !x.is_ascii_whitespace() && *x != '_')
745746
.all(char::is_lowercase)
746747
}
747748

0 commit comments

Comments
 (0)