You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Simplify double quote preference in string
This commit is contained in:
@@ -24,7 +24,7 @@ scanners, e.g. for Python 2.7 or 3.4.
|
|||||||
from array import array
|
from array import array
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import Optional, Tuple, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
import xdis
|
import xdis
|
||||||
from xdis import (
|
from xdis import (
|
||||||
@@ -654,9 +654,9 @@ def prefer_double_quote(string: str) -> str:
|
|||||||
Prefer a double quoted string over a
|
Prefer a double quoted string over a
|
||||||
single quoted string when possible
|
single quoted string when possible
|
||||||
"""
|
"""
|
||||||
if string.find("'") == -1:
|
if string.find("'") == -1 and not string.startswith("'''"):
|
||||||
return f'"{string}"'
|
return f'"{string[1:-2]}"'
|
||||||
return repr(string)
|
return string
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@@ -612,7 +612,7 @@ class Scanner3(Scanner):
|
|||||||
pattr = "<code_object " + co_name + ">"
|
pattr = "<code_object " + co_name + ">"
|
||||||
elif isinstance(const, str):
|
elif isinstance(const, str):
|
||||||
opname = "LOAD_STR"
|
opname = "LOAD_STR"
|
||||||
pattr = prefer_double_quote(inst.argval)
|
pattr = prefer_double_quote(inst.argrepr)
|
||||||
else:
|
else:
|
||||||
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
|
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
|
||||||
argval, _ = _get_const_info(inst.arg, co.co_consts)
|
argval, _ = _get_const_info(inst.arg, co.co_consts)
|
||||||
|
@@ -386,7 +386,7 @@ class Scanner37Base(Scanner):
|
|||||||
pattr = "<code_object " + const.co_name + ">"
|
pattr = "<code_object " + const.co_name + ">"
|
||||||
elif isinstance(const, str):
|
elif isinstance(const, str):
|
||||||
opname = "LOAD_STR"
|
opname = "LOAD_STR"
|
||||||
pattr = prefer_double_quote(inst.argval)
|
pattr = prefer_double_quote(inst.argrepr)
|
||||||
else:
|
else:
|
||||||
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
|
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
|
||||||
argval, _ = _get_const_info(inst.arg, co.co_consts)
|
argval, _ = _get_const_info(inst.arg, co.co_consts)
|
||||||
|
Reference in New Issue
Block a user