simplify withas (for now)

This commit is contained in:
rocky
2024-03-06 17:19:57 -05:00
parent 33f49849f5
commit f1169af582
7 changed files with 34 additions and 23 deletions

View File

@@ -1,7 +1,12 @@
#!/bin/bash #!/bin/bash
# Run tests over all Python versions in branch python-3.0-3.2 # Run tests over all Python versions in branch python-3.0-3.2
set -e
function finish {
cd $owd
}
owd=$(pwd) owd=$(pwd)
trap finish EXIT
cd $(dirname ${BASH_SOURCE[0]}) cd $(dirname ${BASH_SOURCE[0]})
if ! source ./pyenv-3.0-3.2-versions ; then if ! source ./pyenv-3.0-3.2-versions ; then
@@ -23,4 +28,4 @@ for version in $PYVERSIONS; do
fi fi
echo === $version === echo === $version ===
done done
cd $owd finish

View File

@@ -1,7 +1,7 @@
#/bin/bash #/bin/bash
owd=$(pwd) uncompyle6_merge_24_owd=$(pwd)
cd $(dirname ${BASH_SOURCE[0]}) cd $(dirname ${BASH_SOURCE[0]})
if . ./setup-python-2.4.sh; then if . ./setup-python-2.4.sh; then
git merge python-3.0-to-3.2 git merge python-3.0-to-3.2
fi fi
cd $owd cd $uncompyle6_merge_24_owd

View File

@@ -1,7 +1,7 @@
#/bin/bash #/bin/bash
owd=$(pwd) uncompyle6_merge_30_owd=$(pwd)
cd $(dirname ${BASH_SOURCE[0]}) cd $(dirname ${BASH_SOURCE[0]})
if . ./setup-python-3.0.sh; then if . ./setup-python-3.0.sh; then
git merge python-3.3-to-3.5 git merge python-3.3-to-3.5
fi fi
cd $owd cd $uncompyle6_merge_30_owd

View File

@@ -1,7 +1,7 @@
#/bin/bash #/bin/bash
owd=$(pwd) uncompyle6_merge_33_owd=$(pwd)
cd $(dirname ${BASH_SOURCE[0]}) cd $(dirname ${BASH_SOURCE[0]})
if . ./setup-python-3.3.sh; then if . ./setup-python-3.3.sh; then
git merge master git merge master
fi fi
cd $owd cd $uncompyle6_merge_33_owd

View File

@@ -429,6 +429,10 @@ TABLE_DIRECT = {
"whileelsestmt2": ("%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n", 1, 2, -3), "whileelsestmt2": ("%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n", 1, 2, -3),
"whileelselaststmt": ("%|while %c:\n%+%c%-%|else:\n%+%c%-", 1, 2, -2), "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": ( "expr_stmt": (
"%|%p\n", "%|%p\n",
# When a statement contains only a named_expr (:=) # When a statement contains only a named_expr (:=)

View File

@@ -17,23 +17,24 @@
from uncompyle6.semantics.consts import TABLE_DIRECT from uncompyle6.semantics.consts import TABLE_DIRECT
####################### #######################
# Python 2.5+ Changes # # Python 2.5+ Changes #
####################### #######################
def customize_for_version25(self, version): def customize_for_version25(self, version):
######################## ########################
# Import style for 2.5+ # Import style for 2.5+
######################## ########################
TABLE_DIRECT.update({ TABLE_DIRECT.update(
'importmultiple': ( '%|import %c%c\n', 2, 3 ), {
'import_cont' : ( ', %c', 2 ), "importmultiple": ("%|import %c%c\n", 2, 3),
"import_cont": (", %c", 2),
# With/as is allowed as "from future" thing in 2.5 # With/as is allowed as "from future" thing in 2.5
# Note: It is safe to put the variables after "as" in parenthesis, # Note: It is safe to put the variables after "as" in parenthesis,
# and sometimes it is needed. # and sometimes it is needed.
'with': ( '%|with %c:\n%+%c%-', 0, 3), "with": ("%|with %c:\n%+%c%-", 0, 3),
'withasstmt': ( '%|with %c as (%c):\n%+%c%-', 0, 2, 3), }
}) )
# In 2.5+ "except" handlers and the "finally" can appear in one # In 2.5+ "except" handlers and the "finally" can appear in one
# "try" statement. So the below has the effect of combining the # "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 # FIXME: something doesn't smell right, since the semantics
# are different. See test_fileio.py for an example that shows this. # are different. See test_fileio.py for an example that shows this.
def tryfinallystmt(node): def tryfinallystmt(node):
if len(node[1][0]) == 1 and node[1][0][0] == 'stmt': if len(node[1][0]) == 1 and node[1][0][0] == "stmt":
if node[1][0][0][0] == 'try_except': if node[1][0][0][0] == "try_except":
node[1][0][0][0].kind = 'tf_try_except' node[1][0][0][0].kind = "tf_try_except"
if node[1][0][0][0] == 'tryelsestmt': if node[1][0][0][0] == "tryelsestmt":
node[1][0][0][0].kind = 'tf_tryelsestmt' node[1][0][0][0].kind = "tf_tryelsestmt"
self.default(node) self.default(node)
self.n_tryfinallystmt = tryfinallystmt self.n_tryfinallystmt = tryfinallystmt
def n_import_from(node): def n_import_from(node):
if node[0].pattr > 0: if node[0].pattr > 0:
node[2].pattr = ("." * node[0].pattr) + node[2].pattr node[2].pattr = ("." * node[0].pattr) + node[2].pattr
self.default(node) self.default(node)
self.n_import_from = n_import_from self.n_import_from = n_import_from

View File

@@ -51,7 +51,6 @@ def customize_for_version3(self, version):
"tf_tryelsestmtl3": ("%c%-%c%|else:\n%+%c", 1, 3, 5), "tf_tryelsestmtl3": ("%c%-%c%|else:\n%+%c", 1, 3, 5),
"store_locals": ("%|# inspect.currentframe().f_locals = __locals__\n",), "store_locals": ("%|# inspect.currentframe().f_locals = __locals__\n",),
"with": ("%|with %c:\n%+%c%-", 0, 3), "with": ("%|with %c:\n%+%c%-", 0, 3),
"withasstmt": ("%|with %c as (%c):\n%+%c%-", 0, 2, 3),
} }
) )