1 """Fixer for sys.exc_{type, value, traceback}
3 sys.exc_type -> sys.exc_info()[0]
4 sys.exc_value -> sys.exc_info()[1]
5 sys.exc_traceback -> sys.exc_info()[2]
8 # By Jeff Balogh and Benjamin Peterson
11 from .. import fixer_base
12 from ..fixer_util
import Attr
, Call
, Name
, Number
, Subscript
, Node
, syms
14 class FixSysExc(fixer_base
.BaseFix
):
15 # This order matches the ordering of sys.exc_info().
16 exc_info
= ["exc_type", "exc_value", "exc_traceback"]
18 power< 'sys' trailer< dot='.' attribute=(%s) > >
19 """ % '|'.join("'%s'" % e
for e
in exc_info
)
21 def transform(self
, node
, results
):
22 sys_attr
= results
["attribute"][0]
23 index
= Number(self
.exc_info
.index(sys_attr
.value
))
25 call
= Call(Name(u
"exc_info"), prefix
=sys_attr
.prefix
)
26 attr
= Attr(Name(u
"sys"), call
)
27 attr
[1].children
[0].prefix
= results
["dot"].prefix
28 attr
.append(Subscript(index
))
29 return Node(syms
.power
, attr
, prefix
=node
.prefix
)