Skip to content

Commit cbb9f07

Browse files
author
rocky
committed
Improve marshal Python 2.0 code from Python 3.
1 parent 9c6aec4 commit cbb9f07

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

xdis/marsh.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,12 @@ def dump_tuple(self, tuple_object: tuple, flag_ref: int = 0) -> None:
583583
dispatch[TYPE_LIST] = dump_tuple
584584

585585
def dump_unicode(self, s, flag_ref: int = 0) -> None:
586-
type_code = TYPE_STRING if self.python_version < (2, 0) else TYPE_UNICODE
586+
if self.python_version < (2, 0):
587+
type_code = TYPE_STRING
588+
elif (2, 0) <= self.python_version <= (3, 0):
589+
type_code = TYPE_INTERNED
590+
else:
591+
type_code = TYPE_UNICODE
587592

588593
if flag_ref:
589594
if (ref := self.intern_objects.get(s, None)) is not None:
@@ -1243,7 +1248,7 @@ def dumps(
12431248
else:
12441249
buf.append(b)
12451250

1246-
return "".join(buf)
1251+
return b"".join(buf)
12471252

12481253

12491254
@builtinify

0 commit comments

Comments
 (0)