@@ -49,10 +49,6 @@ STATIC mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str);
4949STATIC NORETURN void bad_implicit_conversion (mp_obj_t self_in );
5050STATIC NORETURN void arg_type_mixup ();
5151
52- STATIC bool is_str_or_bytes (mp_obj_t o ) {
53- return MP_OBJ_IS_STR (o ) || MP_OBJ_IS_TYPE (o , & mp_type_bytes );
54- }
55-
5652/******************************************************************************/
5753/* str */
5854
@@ -251,6 +247,9 @@ STATIC const byte *find_subbytes(const byte *haystack, mp_uint_t hlen, const byt
251247 return NULL ;
252248}
253249
250+ // Note: this function is used to check if an object is a str or bytes, which
251+ // works because both those types use it as their binary_op method. Revisit
252+ // MP_OBJ_IS_STR_OR_BYTES if this fact changes.
254253mp_obj_t mp_obj_str_binary_op (int op , mp_obj_t lhs_in , mp_obj_t rhs_in ) {
255254 GET_STR_DATA_LEN (lhs_in , lhs_data , lhs_len );
256255 mp_obj_type_t * lhs_type = mp_obj_get_type (lhs_in );
@@ -388,7 +387,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
388387}
389388
390389STATIC mp_obj_t str_join (mp_obj_t self_in , mp_obj_t arg ) {
391- assert (is_str_or_bytes (self_in ));
390+ assert (MP_OBJ_IS_STR_OR_BYTES (self_in ));
392391 const mp_obj_type_t * self_type = mp_obj_get_type (self_in );
393392
394393 // get separation string
@@ -660,7 +659,7 @@ enum { LSTRIP, RSTRIP, STRIP };
660659
661660STATIC mp_obj_t str_uni_strip (int type , uint n_args , const mp_obj_t * args ) {
662661 assert (1 <= n_args && n_args <= 2 );
663- assert (is_str_or_bytes (args [0 ]));
662+ assert (MP_OBJ_IS_STR_OR_BYTES (args [0 ]));
664663 const mp_obj_type_t * self_type = mp_obj_get_type (args [0 ]);
665664
666665 const byte * chars_to_del ;
@@ -1477,7 +1476,7 @@ STATIC mp_obj_t str_count(uint n_args, const mp_obj_t *args) {
14771476}
14781477
14791478STATIC mp_obj_t str_partitioner (mp_obj_t self_in , mp_obj_t arg , mp_int_t direction ) {
1480- if (!is_str_or_bytes (self_in )) {
1479+ if (!MP_OBJ_IS_STR_OR_BYTES (self_in )) {
14811480 assert (0 );
14821481 }
14831482 mp_obj_type_t * self_type = mp_obj_get_type (self_in );
@@ -1877,7 +1876,7 @@ const char *mp_obj_str_get_str(mp_obj_t self_in) {
18771876}
18781877
18791878const char * mp_obj_str_get_data (mp_obj_t self_in , uint * len ) {
1880- if (is_str_or_bytes (self_in )) {
1879+ if (MP_OBJ_IS_STR_OR_BYTES (self_in )) {
18811880 GET_STR_DATA_LEN (self_in , s , l );
18821881 * len = l ;
18831882 return (const char * )s ;
0 commit comments