Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python2..../lib2to3/fixes
File: fix_isinstance.py
# Copyright 2008 Armin Ronacher.
[0] Fix | Delete
# Licensed to PSF under a Contributor Agreement.
[1] Fix | Delete
[2] Fix | Delete
"""Fixer that cleans up a tuple argument to isinstance after the tokens
[3] Fix | Delete
in it were fixed. This is mainly used to remove double occurrences of
[4] Fix | Delete
tokens as a leftover of the long -> int / unicode -> str conversion.
[5] Fix | Delete
[6] Fix | Delete
eg. isinstance(x, (int, long)) -> isinstance(x, (int, int))
[7] Fix | Delete
-> isinstance(x, int)
[8] Fix | Delete
"""
[9] Fix | Delete
[10] Fix | Delete
from .. import fixer_base
[11] Fix | Delete
from ..fixer_util import token
[12] Fix | Delete
[13] Fix | Delete
[14] Fix | Delete
class FixIsinstance(fixer_base.BaseFix):
[15] Fix | Delete
BM_compatible = True
[16] Fix | Delete
PATTERN = """
[17] Fix | Delete
power<
[18] Fix | Delete
'isinstance'
[19] Fix | Delete
trailer< '(' arglist< any ',' atom< '('
[20] Fix | Delete
args=testlist_gexp< any+ >
[21] Fix | Delete
')' > > ')' >
[22] Fix | Delete
>
[23] Fix | Delete
"""
[24] Fix | Delete
[25] Fix | Delete
run_order = 6
[26] Fix | Delete
[27] Fix | Delete
def transform(self, node, results):
[28] Fix | Delete
names_inserted = set()
[29] Fix | Delete
testlist = results["args"]
[30] Fix | Delete
args = testlist.children
[31] Fix | Delete
new_args = []
[32] Fix | Delete
iterator = enumerate(args)
[33] Fix | Delete
for idx, arg in iterator:
[34] Fix | Delete
if arg.type == token.NAME and arg.value in names_inserted:
[35] Fix | Delete
if idx < len(args) - 1 and args[idx + 1].type == token.COMMA:
[36] Fix | Delete
iterator.next()
[37] Fix | Delete
continue
[38] Fix | Delete
else:
[39] Fix | Delete
new_args.append(arg)
[40] Fix | Delete
if arg.type == token.NAME:
[41] Fix | Delete
names_inserted.add(arg.value)
[42] Fix | Delete
if new_args and new_args[-1].type == token.COMMA:
[43] Fix | Delete
del new_args[-1]
[44] Fix | Delete
if len(new_args) == 1:
[45] Fix | Delete
atom = testlist.parent
[46] Fix | Delete
new_args[0].prefix = atom.prefix
[47] Fix | Delete
atom.replace(new_args[0])
[48] Fix | Delete
else:
[49] Fix | Delete
args[:] = new_args
[50] Fix | Delete
node.changed()
[51] Fix | Delete
[52] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function