ยปCore Development>Code coverage>Lib/lib2to3/fixes/fix_sys_exc.py

Python code coverage for Lib/lib2to3/fixes/fix_sys_exc.py

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