Skip to content

Commit 12968fb

Browse files
committed
Display \r and \t escape codes in string repr
1 parent 72d70cb commit 12968fb

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

py/objstr.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ void mp_str_print_quoted(void (*print)(void *env, const char *fmt, ...), void *e
6363
print(env, "%c", *s);
6464
} else if (*s == '\n') {
6565
print(env, "\\n");
66-
// TODO add more escape codes here if we want to match CPython
66+
} else if (*s == '\r') {
67+
print(env, "\\r");
68+
} else if (*s == '\t') {
69+
print(env, "\\t");
6770
} else {
6871
print(env, "\\x%02x", *s);
6972
}

tests/basics/string-repr.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# anything above 0xa0 is printed as Unicode by CPython3.3
2+
for c in range(0xa1):
3+
print("0x%02x: %s" % (c, repr(chr(c))))

0 commit comments

Comments
 (0)