From 19bd82a6df922832cd2f9177c84da5549a5203ba Mon Sep 17 00:00:00 2001 From: Charles G Waldman Date: Sun, 4 Oct 2026 17:28:23 -0500 Subject: [PATCH] fix for issue 528 - quoting string literals in list/dict/set --- test/bytecode_2.7_run/05_string_constants.pyc | Bin 0 -> 466 bytes test/bytecode_3.6_run/05_string_constants.pyc | Bin 0 -> 394 bytes .../bug27+/05_string_constants.py | 13 +++++++++ uncompyle6/semantics/n_actions.py | 27 +++++++++++++----- 4 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 test/bytecode_2.7_run/05_string_constants.pyc create mode 100644 test/bytecode_3.6_run/05_string_constants.pyc create mode 100644 test/simple_source/bug27+/05_string_constants.py diff --git a/test/bytecode_2.7_run/05_string_constants.pyc b/test/bytecode_2.7_run/05_string_constants.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0bc8f9e130e2df166264bfb4bebb3495942579e4 GIT binary patch literal 466 zcmZvYu};G<5QfibnubCPVn9NbP}#x&Wg#pGfdm_3DN~jx%DJg&lT@}VV57VOJ2M@4 z3EqI`U;v37aTgV_5GkLX|305jseQGYPj9c+DJ-4_tta%F7XkuAL;;ZibO39BE?^zd z18e~LkToE3KvA;9LWoV4LR@Am#1+;;Y_S?fbo##@L+aszq*5C;NgO#~W?<{^K$rR; zT^M;_9v6wEESeG!+64fV1bH*WKMxe<6ZqztWlt;VEfNA-^#W9v?99zENw&F#_vxg`WZk(2du}NXg-sH~uR6oi~oQ~x&&uF-% P=Xjzcc0|Y75bNRxiqKgO literal 0 HcmV?d00001 diff --git a/test/bytecode_3.6_run/05_string_constants.pyc b/test/bytecode_3.6_run/05_string_constants.pyc new file mode 100644 index 0000000000000000000000000000000000000000..70d68321e50b73adc23d8cb5e6825cf29b85f2c4 GIT binary patch literal 394 zcmY+||?3V90o?c%rPADO7;FXJhFmaMSSH|2nCe&d0|ig;iKEU<78ZEe^Rbuw_JRTF zF5a%5C8_F6WjU6^yn|7RY_uLHBA%qhc&)}=N&R7XHhdd)4DW_JMDvjpP=A_wX4o~{ zBcXkjX8EvdONN!S47S01Sb9k9Ag5hNyHNyX97UR5YueZJNYjCC9V#Vcm6pY^l%<>z zxnv$1zE*lwKJ9I8N2-#zXcU))s)j|SHl{b)+sjM1%)~y&QPn~?= (3, 0): + return elem.pattr + data = elem.pattr + if isinstance(data, (float, complex)): + return better_repr(data, self.version) + return repr(data) + def n_const_list(self, node: SyntaxTree): """ prettyprint a constant dict, list, set or tuple. @@ -242,13 +258,10 @@ def n_const_list(self, node: SyntaxTree): assert elem.kind == "ADD_VALUE" if elem.optype in ("local", "name"): value = elem.attr - elif elem.optype == "const" and not isinstance(elem.attr, str): - value = elem.attr + elif elem.optype == "const": + value = self.format_const(elem) else: - try: - value = "%r" % elem.pattr - except Exception: - value = elem.pattr + value = elem.pattr if elem.linestart is not None: if elem.linestart != self.line_number: next_indent = self.indent + INDENT_PER_LEVEL[:-1] @@ -276,7 +289,7 @@ def n_const_list(self, node: SyntaxTree): if elem.optype in ("local", "name"): value = elem.attr elif elem.optype == "const": - value = elem.pattr + value = self.format_const(elem) else: value = "%s" % repr(elem.attr) else: