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

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

#countcontent
1n/a# Copyright 2006 Google, Inc. All Rights Reserved.
2n/a# Licensed to PSF under a Contributor Agreement.
3n/a
4n/a"""Fixer for exec.
5n/a
6n/aThis converts usages of the exec statement into calls to a built-in
7n/aexec() function.
8n/a
9n/aexec code in ns1, ns2 -> exec(code, ns1, ns2)
10n/a"""
11n/a
12n/a# Local imports
13n/afrom .. import fixer_base
14n/afrom ..fixer_util import Comma, Name, Call
15n/a
16n/a
17n/aclass FixExec(fixer_base.BaseFix):
18n/a BM_compatible = True
19n/a
20n/a PATTERN = """
21n/a exec_stmt< 'exec' a=any 'in' b=any [',' c=any] >
22n/a |
23n/a exec_stmt< 'exec' (not atom<'(' [any] ')'>) a=any >
24n/a """
25n/a
26n/a def transform(self, node, results):
27n/a assert results
28n/a syms = self.syms
29n/a a = results["a"]
30n/a b = results.get("b")
31n/a c = results.get("c")
32n/a args = [a.clone()]
33n/a args[0].prefix = ""
34n/a if b is not None:
35n/a args.extend([Comma(), b.clone()])
36n/a if c is not None:
37n/a args.extend([Comma(), c.clone()])
38n/a
39n/a return Call(Name("exec"), args, prefix=node.prefix)