You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Better fstring handling for FORMAT_VALUE | 0x4
This commit is contained in:
@@ -134,6 +134,10 @@ if PYTHON_VERSION > 2.6:
|
|||||||
deparsed = deparse_code(PYTHON_VERSION, code, compile_mode='single')
|
deparsed = deparse_code(PYTHON_VERSION, code, compile_mode='single')
|
||||||
recompiled = compile(deparsed.text, '<string>', 'single')
|
recompiled = compile(deparsed.text, '<string>', 'single')
|
||||||
if recompiled != code:
|
if recompiled != code:
|
||||||
|
print(recompiled)
|
||||||
|
print('================')
|
||||||
|
print(code)
|
||||||
|
print('----------------')
|
||||||
assert 'dis(' + deparsed.text.strip('\n') + ')' == 'dis(' + expr.strip('\n') + ')'
|
assert 'dis(' + deparsed.text.strip('\n') + ')' == 'dis(' + expr.strip('\n') + ')'
|
||||||
|
|
||||||
|
|
||||||
@@ -144,7 +148,7 @@ if PYTHON_VERSION > 2.6:
|
|||||||
run_test(fstring)
|
run_test(fstring)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(PYTHON_VERSION < 3.6, reason='need Python 3.6+')
|
@pytest.mark.skipif(PYTHON_VERSION != 3.6, reason='need Python 3.6+')
|
||||||
@pytest.mark.parametrize('fstring', [
|
@pytest.mark.parametrize('fstring', [
|
||||||
"f'{abc}{abc!s}'",
|
"f'{abc}{abc!s}'",
|
||||||
"f'{abc}0'",
|
"f'{abc}0'",
|
||||||
|
@@ -189,12 +189,16 @@ class Python36Parser(Python35Parser):
|
|||||||
expr ::= fstring_expr
|
expr ::= fstring_expr
|
||||||
fstring_expr ::= expr FORMAT_VALUE
|
fstring_expr ::= expr FORMAT_VALUE
|
||||||
|
|
||||||
# FIXME: need to look inside FORMAT_VALUE to see if 4
|
|
||||||
fstring_single ::= expr expr FORMAT_VALUE
|
|
||||||
str ::= LOAD_CONST
|
str ::= LOAD_CONST
|
||||||
formatted_value ::= fstring_expr
|
formatted_value ::= fstring_expr
|
||||||
formatted_value ::= str
|
formatted_value ::= str
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.add_unique_doc_rules(rules_str, customize)
|
||||||
|
elif opname == 'FORMAT_VALUE_ATTR':
|
||||||
|
rules_str = """
|
||||||
|
expr ::= fstring_single
|
||||||
|
fstring_single ::= expr expr FORMAT_VALUE_ATTR
|
||||||
"""
|
"""
|
||||||
self.add_unique_doc_rules(rules_str, customize)
|
self.add_unique_doc_rules(rules_str, customize)
|
||||||
elif opname == 'MAKE_FUNCTION_8':
|
elif opname == 'MAKE_FUNCTION_8':
|
||||||
|
@@ -34,7 +34,11 @@ class Scanner36(Scanner3):
|
|||||||
t.kind = 'CALL_FUNCTION_EX_KW'
|
t.kind = 'CALL_FUNCTION_EX_KW'
|
||||||
pass
|
pass
|
||||||
elif t.op == self.opc.CALL_FUNCTION_KW:
|
elif t.op == self.opc.CALL_FUNCTION_KW:
|
||||||
t.kind = 'CALL_FUNCTION_KW_{t.attr}'.format(**locals())
|
t.kind = 'CALL_FUNCTION_KW_%s' % t.attr
|
||||||
|
elif t.op == self.opc.FORMAT_VALUE:
|
||||||
|
if (t.attr & 0x4):
|
||||||
|
t.kind = 'FORMAT_VALUE_ATTR'
|
||||||
|
pass
|
||||||
elif ( not_pypy36 and
|
elif ( not_pypy36 and
|
||||||
t.op == self.opc.BUILD_MAP_UNPACK_WITH_CALL ):
|
t.op == self.opc.BUILD_MAP_UNPACK_WITH_CALL ):
|
||||||
t.kind = 'BUILD_MAP_UNPACK_WITH_CALL_%d' % t.attr
|
t.kind = 'BUILD_MAP_UNPACK_WITH_CALL_%d' % t.attr
|
||||||
|
Reference in New Issue
Block a user