From f1169af582edae6f7cffff10900ef689c056af6e Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 6 Mar 2024 17:19:57 -0500 Subject: [PATCH] simplify withas (for now) --- admin-tools/check-3.0-3.2-versions.sh | 7 +++++- admin-tools/merge-for-2.4.sh | 4 ++-- admin-tools/merge-for-3.0.sh | 4 ++-- admin-tools/merge-for-3.3.sh | 4 ++-- uncompyle6/semantics/consts.py | 4 ++++ uncompyle6/semantics/customize25.py | 33 +++++++++++++++------------ uncompyle6/semantics/customize3.py | 1 - 7 files changed, 34 insertions(+), 23 deletions(-) diff --git a/admin-tools/check-3.0-3.2-versions.sh b/admin-tools/check-3.0-3.2-versions.sh index 2e4115dd..16fc9741 100644 --- a/admin-tools/check-3.0-3.2-versions.sh +++ b/admin-tools/check-3.0-3.2-versions.sh @@ -1,7 +1,12 @@ #!/bin/bash # Run tests over all Python versions in branch python-3.0-3.2 +set -e +function finish { + cd $owd +} owd=$(pwd) +trap finish EXIT cd $(dirname ${BASH_SOURCE[0]}) if ! source ./pyenv-3.0-3.2-versions ; then @@ -23,4 +28,4 @@ for version in $PYVERSIONS; do fi echo === $version === done -cd $owd +finish diff --git a/admin-tools/merge-for-2.4.sh b/admin-tools/merge-for-2.4.sh index 38b38124..b110e71e 100755 --- a/admin-tools/merge-for-2.4.sh +++ b/admin-tools/merge-for-2.4.sh @@ -1,7 +1,7 @@ #/bin/bash -owd=$(pwd) +uncompyle6_merge_24_owd=$(pwd) cd $(dirname ${BASH_SOURCE[0]}) if . ./setup-python-2.4.sh; then git merge python-3.0-to-3.2 fi -cd $owd +cd $uncompyle6_merge_24_owd diff --git a/admin-tools/merge-for-3.0.sh b/admin-tools/merge-for-3.0.sh index 834e9a25..ef1f9100 100755 --- a/admin-tools/merge-for-3.0.sh +++ b/admin-tools/merge-for-3.0.sh @@ -1,7 +1,7 @@ #/bin/bash -owd=$(pwd) +uncompyle6_merge_30_owd=$(pwd) cd $(dirname ${BASH_SOURCE[0]}) if . ./setup-python-3.0.sh; then git merge python-3.3-to-3.5 fi -cd $owd +cd $uncompyle6_merge_30_owd diff --git a/admin-tools/merge-for-3.3.sh b/admin-tools/merge-for-3.3.sh index 8febb3d9..7915bda3 100755 --- a/admin-tools/merge-for-3.3.sh +++ b/admin-tools/merge-for-3.3.sh @@ -1,7 +1,7 @@ #/bin/bash -owd=$(pwd) +uncompyle6_merge_33_owd=$(pwd) cd $(dirname ${BASH_SOURCE[0]}) if . ./setup-python-3.3.sh; then git merge master fi -cd $owd +cd $uncompyle6_merge_33_owd diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index 73b57f0f..bc62b205 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -429,6 +429,10 @@ TABLE_DIRECT = { "whileelsestmt2": ("%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n", 1, 2, -3), "whileelselaststmt": ("%|while %c:\n%+%c%-%|else:\n%+%c%-", 1, 2, -2), + # If there are situations where we need "with ... as ()" + # We may need to customize this in n_withasstmt + "withasstmt": ("%|with %c as %c:\n%+%c%-", 0, 2, 3), + "expr_stmt": ( "%|%p\n", # When a statement contains only a named_expr (:=) diff --git a/uncompyle6/semantics/customize25.py b/uncompyle6/semantics/customize25.py index 886e9633..ee3a2d44 100644 --- a/uncompyle6/semantics/customize25.py +++ b/uncompyle6/semantics/customize25.py @@ -17,23 +17,24 @@ from uncompyle6.semantics.consts import TABLE_DIRECT + ####################### # Python 2.5+ Changes # ####################### def customize_for_version25(self, version): - ######################## # Import style for 2.5+ ######################## - TABLE_DIRECT.update({ - 'importmultiple': ( '%|import %c%c\n', 2, 3 ), - 'import_cont' : ( ', %c', 2 ), - # With/as is allowed as "from future" thing in 2.5 - # Note: It is safe to put the variables after "as" in parenthesis, - # and sometimes it is needed. - 'with': ( '%|with %c:\n%+%c%-', 0, 3), - 'withasstmt': ( '%|with %c as (%c):\n%+%c%-', 0, 2, 3), - }) + TABLE_DIRECT.update( + { + "importmultiple": ("%|import %c%c\n", 2, 3), + "import_cont": (", %c", 2), + # With/as is allowed as "from future" thing in 2.5 + # Note: It is safe to put the variables after "as" in parenthesis, + # and sometimes it is needed. + "with": ("%|with %c:\n%+%c%-", 0, 3), + } + ) # In 2.5+ "except" handlers and the "finally" can appear in one # "try" statement. So the below has the effect of combining the @@ -41,16 +42,18 @@ def customize_for_version25(self, version): # FIXME: something doesn't smell right, since the semantics # are different. See test_fileio.py for an example that shows this. def tryfinallystmt(node): - if len(node[1][0]) == 1 and node[1][0][0] == 'stmt': - if node[1][0][0][0] == 'try_except': - node[1][0][0][0].kind = 'tf_try_except' - if node[1][0][0][0] == 'tryelsestmt': - node[1][0][0][0].kind = 'tf_tryelsestmt' + if len(node[1][0]) == 1 and node[1][0][0] == "stmt": + if node[1][0][0][0] == "try_except": + node[1][0][0][0].kind = "tf_try_except" + if node[1][0][0][0] == "tryelsestmt": + node[1][0][0][0].kind = "tf_tryelsestmt" self.default(node) + self.n_tryfinallystmt = tryfinallystmt def n_import_from(node): if node[0].pattr > 0: node[2].pattr = ("." * node[0].pattr) + node[2].pattr self.default(node) + self.n_import_from = n_import_from diff --git a/uncompyle6/semantics/customize3.py b/uncompyle6/semantics/customize3.py index c9025c5d..80309c37 100644 --- a/uncompyle6/semantics/customize3.py +++ b/uncompyle6/semantics/customize3.py @@ -51,7 +51,6 @@ def customize_for_version3(self, version): "tf_tryelsestmtl3": ("%c%-%c%|else:\n%+%c", 1, 3, 5), "store_locals": ("%|# inspect.currentframe().f_locals = __locals__\n",), "with": ("%|with %c:\n%+%c%-", 0, 3), - "withasstmt": ("%|with %c as (%c):\n%+%c%-", 0, 2, 3), } )