Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
81ad8ccd
Commit
81ad8ccd
authored
Jun 30, 2010
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Output try-except-finally statements where appropriate.
parent
8d6d7604
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
Demo/parser/test_unparse.py
Demo/parser/test_unparse.py
+15
-1
Demo/parser/unparse.py
Demo/parser/unparse.py
+8
-4
No files found.
Demo/parser/test_unparse.py
View file @
81ad8ccd
...
@@ -80,7 +80,18 @@ elif cond2:
...
@@ -80,7 +80,18 @@ elif cond2:
suite2
suite2
"""
"""
try_except_finally
=
"""
\
try:
suite1
except ex1:
suite2
except ex2:
suite3
else:
suite4
finally:
suite5
"""
class
ASTTestCase
(
unittest
.
TestCase
):
class
ASTTestCase
(
unittest
.
TestCase
):
def
assertASTEqual
(
self
,
ast1
,
ast2
):
def
assertASTEqual
(
self
,
ast1
,
ast2
):
...
@@ -181,6 +192,9 @@ class UnparseTestCase(ASTTestCase):
...
@@ -181,6 +192,9 @@ class UnparseTestCase(ASTTestCase):
self
.
check_roundtrip
(
elif1
)
self
.
check_roundtrip
(
elif1
)
self
.
check_roundtrip
(
elif2
)
self
.
check_roundtrip
(
elif2
)
def
test_try_except_finally
(
self
):
self
.
check_roundtrip
(
try_except_finally
)
class
DirectoryTestCase
(
ASTTestCase
):
class
DirectoryTestCase
(
ASTTestCase
):
"""Test roundtrip behaviour on all files in Lib and Lib/test."""
"""Test roundtrip behaviour on all files in Lib and Lib/test."""
...
...
Demo/parser/unparse.py
View file @
81ad8ccd
...
@@ -169,6 +169,10 @@ class Unparser:
...
@@ -169,6 +169,10 @@ class Unparser:
self
.
leave
()
self
.
leave
()
def
_TryFinally
(
self
,
t
):
def
_TryFinally
(
self
,
t
):
if
len
(
t
.
body
)
==
1
and
isinstance
(
t
.
body
[
0
],
ast
.
TryExcept
):
# try-except-finally
self
.
dispatch
(
t
.
body
)
else
:
self
.
fill
(
"try"
)
self
.
fill
(
"try"
)
self
.
enter
()
self
.
enter
()
self
.
dispatch
(
t
.
body
)
self
.
dispatch
(
t
.
body
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment