]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/lib2to3/fixes/fix_isinstance.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / lib2to3 / fixes / fix_isinstance.py
CommitLineData
4710c53d 1# Copyright 2008 Armin Ronacher.\r
2# Licensed to PSF under a Contributor Agreement.\r
3\r
4"""Fixer that cleans up a tuple argument to isinstance after the tokens\r
5in it were fixed. This is mainly used to remove double occurrences of\r
6tokens as a leftover of the long -> int / unicode -> str conversion.\r
7\r
8eg. isinstance(x, (int, long)) -> isinstance(x, (int, int))\r
9 -> isinstance(x, int)\r
10"""\r
11\r
12from .. import fixer_base\r
13from ..fixer_util import token\r
14\r
15\r
16class FixIsinstance(fixer_base.BaseFix):\r
17 BM_compatible = True\r
18 PATTERN = """\r
19 power<\r
20 'isinstance'\r
21 trailer< '(' arglist< any ',' atom< '('\r
22 args=testlist_gexp< any+ >\r
23 ')' > > ')' >\r
24 >\r
25 """\r
26\r
27 run_order = 6\r
28\r
29 def transform(self, node, results):\r
30 names_inserted = set()\r
31 testlist = results["args"]\r
32 args = testlist.children\r
33 new_args = []\r
34 iterator = enumerate(args)\r
35 for idx, arg in iterator:\r
36 if arg.type == token.NAME and arg.value in names_inserted:\r
37 if idx < len(args) - 1 and args[idx + 1].type == token.COMMA:\r
38 iterator.next()\r
39 continue\r
40 else:\r
41 new_args.append(arg)\r
42 if arg.type == token.NAME:\r
43 names_inserted.add(arg.value)\r
44 if new_args and new_args[-1].type == token.COMMA:\r
45 del new_args[-1]\r
46 if len(new_args) == 1:\r
47 atom = testlist.parent\r
48 new_args[0].prefix = atom.prefix\r
49 atom.replace(new_args[0])\r
50 else:\r
51 args[:] = new_args\r
52 node.changed()\r