You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
3.6+ nested format strings again
This commit is contained in:
Binary file not shown.
@@ -105,3 +105,4 @@ width, precision, value = (10, 4, decimal.Decimal('12.34567'))
|
||||
assert f'result: {value:{width}.{precision}}' == 'result: 12.35'
|
||||
assert f'result: {value:{width:0}.{precision:1}}' == 'result: 12.35'
|
||||
assert f'{2}\t' == '2\t'
|
||||
assert f'{f"{0}"*3}' == "000"
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2019 by Rocky Bernstein
|
||||
# Copyright (c) 2019-2020 by Rocky Bernstein
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -451,13 +451,13 @@ def customize_for_version36(self, version):
|
||||
expr = node[0]
|
||||
assert expr == "expr"
|
||||
conversion = f_conversion(node)
|
||||
if (self.in_format_string):
|
||||
if (self.in_format_string and self.in_format_string != "formatted_value1"):
|
||||
value = self.traverse(expr, indent="")
|
||||
es = escape_string("{%s%s}" % (value, conversion))
|
||||
f_str = "%s" % es
|
||||
else:
|
||||
old_in_format_string = self.in_format_string
|
||||
self.in_format_string = True
|
||||
self.in_format_string = "formatted_value1"
|
||||
value = self.traverse(expr, indent="")
|
||||
self.in_format_string = old_in_format_string
|
||||
es = escape_string("{%s%s}" % (value, conversion))
|
||||
@@ -475,7 +475,7 @@ def customize_for_version36(self, version):
|
||||
expr = node[0]
|
||||
assert expr == "expr"
|
||||
old_in_format_string = self.in_format_string
|
||||
self.in_format_string = True
|
||||
self.in_format_string = "formatted_value2"
|
||||
value = self.traverse(expr, indent="")
|
||||
format_value_attr = node[-1]
|
||||
assert format_value_attr == "FORMAT_VALUE_ATTR"
|
||||
@@ -505,7 +505,7 @@ def customize_for_version36(self, version):
|
||||
self.prec = 100
|
||||
|
||||
old_in_format_string = self.in_format_string
|
||||
self.in_format_string = True
|
||||
self.in_format_string = "joined_str"
|
||||
result = ""
|
||||
for expr in node[:-1]:
|
||||
assert expr == "expr"
|
||||
|
@@ -271,8 +271,11 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.tolerate_errors = tolerate_errors
|
||||
|
||||
# If we are in a 3.6+ format string, we may need an
|
||||
# extra level of parens when seeing a lambda
|
||||
self.in_format_string = False
|
||||
# extra level of parens when seeing a lambda. We also use
|
||||
# this to understand whether or not to add the "f" prefix.
|
||||
# When not "None" it is a string of the last nonterminal
|
||||
# that started the format string
|
||||
self.in_format_string = None
|
||||
|
||||
# hide_internal suppresses displaying the additional instructions that sometimes
|
||||
# exist in code but but were not written in the source code.
|
||||
|
Reference in New Issue
Block a user