+++ /dev/null
-"""Fixer for sys.exc_{type, value, traceback}\r
-\r
-sys.exc_type -> sys.exc_info()[0]\r
-sys.exc_value -> sys.exc_info()[1]\r
-sys.exc_traceback -> sys.exc_info()[2]\r
-"""\r
-\r
-# By Jeff Balogh and Benjamin Peterson\r
-\r
-# Local imports\r
-from .. import fixer_base\r
-from ..fixer_util import Attr, Call, Name, Number, Subscript, Node, syms\r
-\r
-class FixSysExc(fixer_base.BaseFix):\r
- # This order matches the ordering of sys.exc_info().\r
- exc_info = [u"exc_type", u"exc_value", u"exc_traceback"]\r
- BM_compatible = True\r
- PATTERN = """\r
- power< 'sys' trailer< dot='.' attribute=(%s) > >\r
- """ % '|'.join("'%s'" % e for e in exc_info)\r
-\r
- def transform(self, node, results):\r
- sys_attr = results["attribute"][0]\r
- index = Number(self.exc_info.index(sys_attr.value))\r
-\r
- call = Call(Name(u"exc_info"), prefix=sys_attr.prefix)\r
- attr = Attr(Name(u"sys"), call)\r
- attr[1].children[0].prefix = results["dot"].prefix\r
- attr.append(Subscript(index))\r
- return Node(syms.power, attr, prefix=node.prefix)\r