Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

Commit e14b7aa

Browse files
committed
Support byte string literal concatenation
1 parent cb76242 commit e14b7aa

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

rewrite/rewrite/python/_parser_visitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ def visit_Constant(self, node):
12691269
while tok.type in (token.ENCODING, token.NL, token.NEWLINE, token.INDENT, token.DEDENT, token.COMMENT):
12701270
tok = next(tokens)
12711271

1272-
if not isinstance(node.value, str):
1272+
if not isinstance(node.value, (str, bytes)):
12731273
return self.__map_literal(node, tok, tokens)[0]
12741274

12751275
is_byte_string = tok.string.startswith(('b', "B"))
@@ -1327,7 +1327,7 @@ def __map_literal(self, node, tok, tokens):
13271327
def __map_literal_value(self, node, tok):
13281328
if node.value is Ellipsis:
13291329
return None
1330-
elif isinstance(node.value, str):
1330+
elif isinstance(node.value, (str, bytes)):
13311331
return ast.literal_eval(ast.parse(tok.string, mode='eval').body)
13321332
return node.value
13331333

rewrite/tests/python/all/literal_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ def test_large_int():
4040
rewrite_run(python("assert 0xC03A0019"))
4141

4242

43+
def test_byte_string_concatenation():
44+
# language=python
45+
rewrite_run(python("assert b'hello' b'world'"))
46+
47+
4348
def test_bigint():
4449
# language=python
4550
rewrite_run(python("assert 9223372036854775808"))

0 commit comments

Comments
 (0)