Mercurial > cpython-lru_cache-weakref
annotate Lib/lib2to3/fixes/fix_exec.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | b36cb4602e21 |
| children |
| rev | line source |
|---|---|
|
58737
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
1 # Copyright 2006 Google, Inc. All Rights Reserved. |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
2 # Licensed to PSF under a Contributor Agreement. |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
3 |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
4 """Fixer for exec. |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
5 |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
6 This converts usages of the exec statement into calls to a built-in |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
7 exec() function. |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
8 |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
9 exec code in ns1, ns2 -> exec(code, ns1, ns2) |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
10 """ |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
11 |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
12 # Local imports |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
13 from .. import pytree |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
14 from .. import fixer_base |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
15 from ..fixer_util import Comma, Name, Call |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
16 |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
17 |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
18 class FixExec(fixer_base.BaseFix): |
|
65340
7d1e453b120b
Merged revisions 83852-83853,83857,84042,84216,84274-84276,84375,85388,85478,85506-85508 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54696
diff
changeset
|
19 BM_compatible = True |
|
58737
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
20 |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
21 PATTERN = """ |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
22 exec_stmt< 'exec' a=any 'in' b=any [',' c=any] > |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
23 | |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
24 exec_stmt< 'exec' (not atom<'(' [any] ')'>) a=any > |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
25 """ |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
26 |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
27 def transform(self, node, results): |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
28 assert results |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
29 syms = self.syms |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
30 a = results["a"] |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
31 b = results.get("b") |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
32 c = results.get("c") |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
33 args = [a.clone()] |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
34 args[0].prefix = "" |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
35 if b is not None: |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
36 args.extend([Comma(), b.clone()]) |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
37 if c is not None: |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
38 args.extend([Comma(), c.clone()]) |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
39 |
|
fab380674959
copy lib2to3 from the trunk
Benjamin Peterson <benjamin@python.org>
parents:
diff
changeset
|
40 return Call(Name(u"exec"), args, prefix=node.prefix) |
