Skip to content

Commit 0a08b8d

Browse files
committed
Simplify double quote preference in string
1 parent 9f9f6de commit 0a08b8d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

uncompyle6/scanner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from array import array
2525
from collections import namedtuple
2626
from types import ModuleType
27-
from typing import Optional, Tuple, Union
27+
from typing import Optional, Union
2828

2929
import xdis
3030
from xdis import (
@@ -654,9 +654,9 @@ def prefer_double_quote(string: str) -> str:
654654
Prefer a double quoted string over a
655655
single quoted string when possible
656656
"""
657-
if string.find("'") == -1:
658-
return f'"{string}"'
659-
return repr(string)
657+
if string.find("'") == -1 and not string.startswith("'''"):
658+
return f'"{string[1:-2]}"'
659+
return string
660660

661661

662662
if __name__ == "__main__":

uncompyle6/scanners/scanner3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def ingest(
612612
pattr = "<code_object " + co_name + ">"
613613
elif isinstance(const, str):
614614
opname = "LOAD_STR"
615-
pattr = prefer_double_quote(inst.argval)
615+
pattr = prefer_double_quote(inst.argrepr)
616616
else:
617617
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
618618
argval, _ = _get_const_info(inst.arg, co.co_consts)

uncompyle6/scanners/scanner37base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def tokens_append(j, token):
386386
pattr = "<code_object " + const.co_name + ">"
387387
elif isinstance(const, str):
388388
opname = "LOAD_STR"
389-
pattr = prefer_double_quote(inst.argval)
389+
pattr = prefer_double_quote(inst.argrepr)
390390
else:
391391
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
392392
argval, _ = _get_const_info(inst.arg, co.co_consts)

0 commit comments

Comments
 (0)