You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Some limited support for 3.8 "=" specifier
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
#######################
|
||||
|
||||
from uncompyle6.semantics.consts import PRECEDENCE, TABLE_DIRECT
|
||||
from uncompyle6.semantics.customize37 import FSTRING_CONVERSION_MAP
|
||||
from uncompyle6.semantics.helper import escape_string, strip_quotes
|
||||
|
||||
def customize_for_version38(self, version):
|
||||
|
||||
@@ -125,7 +127,7 @@ def customize_for_version38(self, version):
|
||||
"set_for": (" for %c in %c", (2, "store"), (0, "expr_or_arg"),),
|
||||
"whilestmt38": (
|
||||
"%|while %c:\n%+%c%-\n\n",
|
||||
(1, "testexpr"),
|
||||
(1, ("bool_op", "testexpr", "testexprc")),
|
||||
(2, ("l_stmts", "pass")),
|
||||
),
|
||||
"whileTruestmt38": (
|
||||
@@ -282,6 +284,54 @@ def customize_for_version38(self, version):
|
||||
|
||||
self.n_set_afor = n_set_afor
|
||||
|
||||
def n_formatted_value_debug(node):
|
||||
p = self.prec
|
||||
self.prec = 100
|
||||
|
||||
formatted_value = node[1]
|
||||
value_equal = node[0].attr
|
||||
assert formatted_value.kind.startswith("formatted_value")
|
||||
old_in_format_string = self.in_format_string
|
||||
self.in_format_string = formatted_value.kind
|
||||
format_value_attr = node[-1]
|
||||
|
||||
post_str = ""
|
||||
if node[-1] == "BUILD_STRING_3":
|
||||
post_load_str = node[-2]
|
||||
post_str = self.traverse(post_load_str, indent="")
|
||||
post_str = strip_quotes(post_str)
|
||||
|
||||
if format_value_attr == "FORMAT_VALUE_ATTR":
|
||||
attr = format_value_attr.attr
|
||||
if attr & 4:
|
||||
fmt = strip_quotes(self.traverse(node[3], indent=""))
|
||||
attr_flags = attr & 3
|
||||
if attr_flags:
|
||||
conversion = "%s:%s" % (
|
||||
FSTRING_CONVERSION_MAP.get(attr_flags, ""),
|
||||
fmt,
|
||||
)
|
||||
else:
|
||||
conversion = ":%s" % fmt
|
||||
else:
|
||||
conversion = FSTRING_CONVERSION_MAP.get(attr, "")
|
||||
f_str = "f%s" % escape_string(
|
||||
"{%s%s}%s" % (value_equal, conversion, post_str)
|
||||
)
|
||||
else:
|
||||
f_conversion = self.traverse(formatted_value, indent="")
|
||||
# Remove leaving "f" and quotes
|
||||
conversion = strip_quotes(f_conversion[1:])
|
||||
f_str = "f%s" % escape_string(f"{value_equal}{conversion}" + post_str)
|
||||
|
||||
self.write(f_str)
|
||||
self.in_format_string = old_in_format_string
|
||||
|
||||
self.prec = p
|
||||
self.prune()
|
||||
|
||||
self.n_formatted_value_debug = n_formatted_value_debug
|
||||
|
||||
def n_suite_stmts_return(node):
|
||||
if len(node) > 1:
|
||||
assert len(node) == 2
|
||||
|
Reference in New Issue
Block a user