mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Collapse else: if: ... into elif:
This commit is contained in:
parent
719e4e3ba5
commit
8d6d760422
2 changed files with 32 additions and 1 deletions
|
@ -256,9 +256,18 @@ class Unparser:
|
|||
self.fill("if ")
|
||||
self.dispatch(t.test)
|
||||
self.enter()
|
||||
# XXX elif?
|
||||
self.dispatch(t.body)
|
||||
self.leave()
|
||||
# collapse nested ifs into equivalent elifs.
|
||||
while (t.orelse and len(t.orelse) == 1 and
|
||||
isinstance(t.orelse[0], ast.If)):
|
||||
t = t.orelse[0]
|
||||
self.fill("elif ")
|
||||
self.dispatch(t.test)
|
||||
self.enter()
|
||||
self.dispatch(t.body)
|
||||
self.leave()
|
||||
# final else
|
||||
if t.orelse:
|
||||
self.fill("else")
|
||||
self.enter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue