Skip to content

Commit f1169af

Browse files
committed
simplify withas (for now)
1 parent 33f4984 commit f1169af

File tree

7 files changed

+34
-23
lines changed

7 files changed

+34
-23
lines changed

admin-tools/check-3.0-3.2-versions.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/bin/bash
22
# Run tests over all Python versions in branch python-3.0-3.2
3+
set -e
4+
function finish {
5+
cd $owd
6+
}
37

48
owd=$(pwd)
9+
trap finish EXIT
510

611
cd $(dirname ${BASH_SOURCE[0]})
712
if ! source ./pyenv-3.0-3.2-versions ; then
@@ -23,4 +28,4 @@ for version in $PYVERSIONS; do
2328
fi
2429
echo === $version ===
2530
done
26-
cd $owd
31+
finish

admin-tools/merge-for-2.4.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/bin/bash
2-
owd=$(pwd)
2+
uncompyle6_merge_24_owd=$(pwd)
33
cd $(dirname ${BASH_SOURCE[0]})
44
if . ./setup-python-2.4.sh; then
55
git merge python-3.0-to-3.2
66
fi
7-
cd $owd
7+
cd $uncompyle6_merge_24_owd

admin-tools/merge-for-3.0.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/bin/bash
2-
owd=$(pwd)
2+
uncompyle6_merge_30_owd=$(pwd)
33
cd $(dirname ${BASH_SOURCE[0]})
44
if . ./setup-python-3.0.sh; then
55
git merge python-3.3-to-3.5
66
fi
7-
cd $owd
7+
cd $uncompyle6_merge_30_owd

admin-tools/merge-for-3.3.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/bin/bash
2-
owd=$(pwd)
2+
uncompyle6_merge_33_owd=$(pwd)
33
cd $(dirname ${BASH_SOURCE[0]})
44
if . ./setup-python-3.3.sh; then
55
git merge master
66
fi
7-
cd $owd
7+
cd $uncompyle6_merge_33_owd

uncompyle6/semantics/consts.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@
429429
"whileelsestmt2": ("%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n", 1, 2, -3),
430430
"whileelselaststmt": ("%|while %c:\n%+%c%-%|else:\n%+%c%-", 1, 2, -2),
431431

432+
# If there are situations where we need "with ... as ()"
433+
# We may need to customize this in n_withasstmt
434+
"withasstmt": ("%|with %c as %c:\n%+%c%-", 0, 2, 3),
435+
432436
"expr_stmt": (
433437
"%|%p\n",
434438
# When a statement contains only a named_expr (:=)

uncompyle6/semantics/customize25.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,43 @@
1717

1818
from uncompyle6.semantics.consts import TABLE_DIRECT
1919

20+
2021
#######################
2122
# Python 2.5+ Changes #
2223
#######################
2324
def customize_for_version25(self, version):
24-
2525
########################
2626
# Import style for 2.5+
2727
########################
28-
TABLE_DIRECT.update({
29-
'importmultiple': ( '%|import %c%c\n', 2, 3 ),
30-
'import_cont' : ( ', %c', 2 ),
31-
# With/as is allowed as "from future" thing in 2.5
32-
# Note: It is safe to put the variables after "as" in parenthesis,
33-
# and sometimes it is needed.
34-
'with': ( '%|with %c:\n%+%c%-', 0, 3),
35-
'withasstmt': ( '%|with %c as (%c):\n%+%c%-', 0, 2, 3),
36-
})
28+
TABLE_DIRECT.update(
29+
{
30+
"importmultiple": ("%|import %c%c\n", 2, 3),
31+
"import_cont": (", %c", 2),
32+
# With/as is allowed as "from future" thing in 2.5
33+
# Note: It is safe to put the variables after "as" in parenthesis,
34+
# and sometimes it is needed.
35+
"with": ("%|with %c:\n%+%c%-", 0, 3),
36+
}
37+
)
3738

3839
# In 2.5+ "except" handlers and the "finally" can appear in one
3940
# "try" statement. So the below has the effect of combining the
4041
# "tryfinally" with statement with the "try_except" statement.
4142
# FIXME: something doesn't smell right, since the semantics
4243
# are different. See test_fileio.py for an example that shows this.
4344
def tryfinallystmt(node):
44-
if len(node[1][0]) == 1 and node[1][0][0] == 'stmt':
45-
if node[1][0][0][0] == 'try_except':
46-
node[1][0][0][0].kind = 'tf_try_except'
47-
if node[1][0][0][0] == 'tryelsestmt':
48-
node[1][0][0][0].kind = 'tf_tryelsestmt'
45+
if len(node[1][0]) == 1 and node[1][0][0] == "stmt":
46+
if node[1][0][0][0] == "try_except":
47+
node[1][0][0][0].kind = "tf_try_except"
48+
if node[1][0][0][0] == "tryelsestmt":
49+
node[1][0][0][0].kind = "tf_tryelsestmt"
4950
self.default(node)
51+
5052
self.n_tryfinallystmt = tryfinallystmt
5153

5254
def n_import_from(node):
5355
if node[0].pattr > 0:
5456
node[2].pattr = ("." * node[0].pattr) + node[2].pattr
5557
self.default(node)
58+
5659
self.n_import_from = n_import_from

uncompyle6/semantics/customize3.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def customize_for_version3(self, version):
5151
"tf_tryelsestmtl3": ("%c%-%c%|else:\n%+%c", 1, 3, 5),
5252
"store_locals": ("%|# inspect.currentframe().f_locals = __locals__\n",),
5353
"with": ("%|with %c:\n%+%c%-", 0, 3),
54-
"withasstmt": ("%|with %c as (%c):\n%+%c%-", 0, 2, 3),
5554
}
5655
)
5756

0 commit comments

Comments
 (0)