py: Make bytes objs work with more str methods; add tests.
diff --git a/py/objstr.c b/py/objstr.c
index 7cd4447..16ee2ea 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -46,7 +46,6 @@
 mp_obj_t mp_obj_new_str_iterator(mp_obj_t str);
 STATIC mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str);
 STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in);
-STATIC NORETURN void arg_type_mixup(void);
 
 /******************************************************************************/
 /* str                                                                        */
@@ -525,7 +524,7 @@
     } else {
         // sep given
         if (mp_obj_get_type(sep) != self_type) {
-            arg_type_mixup();
+            bad_implicit_conversion(sep);
         }
 
         mp_uint_t sep_len;
@@ -627,7 +626,7 @@
     assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
 
     // check argument type
-    if (!MP_OBJ_IS_STR(args[1])) {
+    if (mp_obj_get_type(args[1]) != self_type) {
         bad_implicit_conversion(args[1]);
     }
 
@@ -720,7 +719,7 @@
         chars_to_del_len = sizeof(whitespace);
     } else {
         if (mp_obj_get_type(args[1]) != self_type) {
-            arg_type_mixup();
+            bad_implicit_conversion(args[1]);
         }
         GET_STR_DATA_LEN(args[1], s, l);
         chars_to_del = s;
@@ -759,7 +758,11 @@
 
     if (!first_good_char_pos_set) {
         // string is all whitespace, return ''
-        return MP_OBJ_NEW_QSTR(MP_QSTR_);
+        if (self_type == &mp_type_str) {
+            return MP_OBJ_NEW_QSTR(MP_QSTR_);
+        } else {
+            return mp_const_empty_bytes;
+        }
     }
 
     assert(last_good_char_pos >= first_good_char_pos);
@@ -1470,11 +1473,13 @@
 
     // check argument types
 
-    if (!MP_OBJ_IS_STR(args[1])) {
+    const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
+
+    if (mp_obj_get_type(args[1]) != self_type) {
         bad_implicit_conversion(args[1]);
     }
 
-    if (!MP_OBJ_IS_STR(args[2])) {
+    if (mp_obj_get_type(args[2]) != self_type) {
         bad_implicit_conversion(args[2]);
     }
 
@@ -1543,7 +1548,7 @@
                 return args[0];
             } else {
                 // substr found, allocate new string
-                replaced_str = mp_obj_str_builder_start(mp_obj_get_type(args[0]), replaced_str_index, &data);
+                replaced_str = mp_obj_str_builder_start(self_type, replaced_str_index, &data);
                 assert(data != NULL);
             }
         } else {
@@ -1561,7 +1566,7 @@
     assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
 
     // check argument type
-    if (!MP_OBJ_IS_STR(args[1])) {
+    if (mp_obj_get_type(args[1]) != self_type) {
         bad_implicit_conversion(args[1]);
     }
 
@@ -1597,12 +1602,10 @@
 }
 
 STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, mp_int_t direction) {
-    if (!MP_OBJ_IS_STR_OR_BYTES(self_in)) {
-        assert(0);
-    }
+    assert(MP_OBJ_IS_STR_OR_BYTES(self_in));
     mp_obj_type_t *self_type = mp_obj_get_type(self_in);
     if (self_type != mp_obj_get_type(arg)) {
-        arg_type_mixup();
+        bad_implicit_conversion(arg);
     }
 
     GET_STR_DATA_LEN(self_in, str, str_len);
@@ -1612,7 +1615,16 @@
         nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "empty separator"));
     }
 
-    mp_obj_t result[] = {MP_OBJ_NEW_QSTR(MP_QSTR_), MP_OBJ_NEW_QSTR(MP_QSTR_), MP_OBJ_NEW_QSTR(MP_QSTR_)};
+    mp_obj_t result[3];
+    if (self_type == &mp_type_str) {
+        result[0] = MP_OBJ_NEW_QSTR(MP_QSTR_);
+        result[1] = MP_OBJ_NEW_QSTR(MP_QSTR_);
+        result[2] = MP_OBJ_NEW_QSTR(MP_QSTR_);
+    } else {
+        result[0] = mp_const_empty_bytes;
+        result[1] = mp_const_empty_bytes;
+        result[2] = mp_const_empty_bytes;
+    }
 
     if (direction > 0) {
         result[0] = self_in;
@@ -1953,10 +1965,6 @@
     }
 }
 
-STATIC void arg_type_mixup(void) {
-    nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Can't mix str and bytes arguments"));
-}
-
 mp_uint_t mp_obj_str_get_hash(mp_obj_t self_in) {
     // TODO: This has too big overhead for hash accessor
     if (MP_OBJ_IS_STR_OR_BYTES(self_in)) {