Skip to content

Commit

Permalink
Merge pull request #487 from rocky/withasstmt-no-parens
Browse files Browse the repository at this point in the history
simplify withas (for now)
  • Loading branch information
rocky authored Mar 6, 2024
2 parents 33f4984 + f1169af commit b5c4e4b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 23 deletions.
7 changes: 6 additions & 1 deletion admin-tools/check-3.0-3.2-versions.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,4 +28,4 @@ for version in $PYVERSIONS; do
fi
echo === $version ===
done
cd $owd
finish
4 changes: 2 additions & 2 deletions admin-tools/merge-for-2.4.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions admin-tools/merge-for-3.0.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions admin-tools/merge-for-3.3.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions uncompyle6/semantics/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@
"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 (:=)
Expand Down
33 changes: 18 additions & 15 deletions uncompyle6/semantics/customize25.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,43 @@

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
# "tryfinally" with statement with the "try_except" statement.
# 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
1 change: 0 additions & 1 deletion uncompyle6/semantics/customize3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
)

Expand Down

0 comments on commit b5c4e4b

Please sign in to comment.