Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../lib2to3/fixes
File: fix_throw.py
"""Fixer for generator.throw(E, V, T).
[0] Fix | Delete
[1] Fix | Delete
g.throw(E) -> g.throw(E)
[2] Fix | Delete
g.throw(E, V) -> g.throw(E(V))
[3] Fix | Delete
g.throw(E, V, T) -> g.throw(E(V).with_traceback(T))
[4] Fix | Delete
[5] Fix | Delete
g.throw("foo"[, V[, T]]) will warn about string exceptions."""
[6] Fix | Delete
# Author: Collin Winter
[7] Fix | Delete
[8] Fix | Delete
# Local imports
[9] Fix | Delete
from .. import pytree
[10] Fix | Delete
from ..pgen2 import token
[11] Fix | Delete
from .. import fixer_base
[12] Fix | Delete
from ..fixer_util import Name, Call, ArgList, Attr, is_tuple
[13] Fix | Delete
[14] Fix | Delete
class FixThrow(fixer_base.BaseFix):
[15] Fix | Delete
BM_compatible = True
[16] Fix | Delete
PATTERN = """
[17] Fix | Delete
power< any trailer< '.' 'throw' >
[18] Fix | Delete
trailer< '(' args=arglist< exc=any ',' val=any [',' tb=any] > ')' >
[19] Fix | Delete
>
[20] Fix | Delete
|
[21] Fix | Delete
power< any trailer< '.' 'throw' > trailer< '(' exc=any ')' > >
[22] Fix | Delete
"""
[23] Fix | Delete
[24] Fix | Delete
def transform(self, node, results):
[25] Fix | Delete
syms = self.syms
[26] Fix | Delete
[27] Fix | Delete
exc = results["exc"].clone()
[28] Fix | Delete
if exc.type is token.STRING:
[29] Fix | Delete
self.cannot_convert(node, "Python 3 does not support string exceptions")
[30] Fix | Delete
return
[31] Fix | Delete
[32] Fix | Delete
# Leave "g.throw(E)" alone
[33] Fix | Delete
val = results.get("val")
[34] Fix | Delete
if val is None:
[35] Fix | Delete
return
[36] Fix | Delete
[37] Fix | Delete
val = val.clone()
[38] Fix | Delete
if is_tuple(val):
[39] Fix | Delete
args = [c.clone() for c in val.children[1:-1]]
[40] Fix | Delete
else:
[41] Fix | Delete
val.prefix = ""
[42] Fix | Delete
args = [val]
[43] Fix | Delete
[44] Fix | Delete
throw_args = results["args"]
[45] Fix | Delete
[46] Fix | Delete
if "tb" in results:
[47] Fix | Delete
tb = results["tb"].clone()
[48] Fix | Delete
tb.prefix = ""
[49] Fix | Delete
[50] Fix | Delete
e = Call(exc, args)
[51] Fix | Delete
with_tb = Attr(e, Name('with_traceback')) + [ArgList([tb])]
[52] Fix | Delete
throw_args.replace(pytree.Node(syms.power, with_tb))
[53] Fix | Delete
else:
[54] Fix | Delete
throw_args.replace(Call(exc, args))
[55] Fix | Delete
[56] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function