Skip to content

Commit 55b11e6

Browse files
committed
py/objstr: For str.endswith(s, start) raise NotImpl instead of assert.
1 parent 0b7a66a commit 55b11e6

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

py/objstr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,9 @@ STATIC mp_obj_t str_startswith(mp_uint_t n_args, const mp_obj_t *args) {
699699
STATIC mp_obj_t str_endswith(mp_uint_t n_args, const mp_obj_t *args) {
700700
GET_STR_DATA_LEN(args[0], str, str_len);
701701
GET_STR_DATA_LEN(args[1], suffix, suffix_len);
702-
assert(n_args == 2);
702+
if (n_args > 2) {
703+
mp_not_implemented("start/end indices");
704+
}
703705

704706
if (suffix_len > str_len) {
705707
return mp_const_false;

tests/misc/non_compliant.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
except NotImplementedError:
5353
print('NotImplementedError')
5454

55+
# str.endswith(s, start) not implemented
56+
try:
57+
'abc'.endswith('c', 1)
58+
except NotImplementedError:
59+
print('NotImplementedError')
60+
5561
# bytes(...) with keywords not implemented
5662
try:
5763
bytes('abc', encoding='utf8')

tests/misc/non_compliant.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ NotImplementedError
88
NotImplementedError
99
NotImplementedError
1010
NotImplementedError
11+
NotImplementedError

0 commit comments

Comments
 (0)