comparison planemo/lib/python3.7/site-packages/libpasteurize/fixes/fix_throw.py @ 1:56ad4e20f292 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:32:28 -0400
parents
children
comparison
equal deleted inserted replaced
0:d30785e31577 1:56ad4e20f292
1 u"""Fixer for 'g.throw(E(V).with_traceback(T))' -> 'g.throw(E, V, T)'"""
2
3 from lib2to3 import fixer_base
4 from lib2to3.pytree import Node, Leaf
5 from lib2to3.pgen2 import token
6 from lib2to3.fixer_util import Comma
7
8 class FixThrow(fixer_base.BaseFix):
9
10 PATTERN = u"""
11 power< any trailer< '.' 'throw' >
12 trailer< '(' args=power< exc=any trailer< '(' val=any* ')' >
13 trailer< '.' 'with_traceback' > trailer< '(' trc=any ')' > > ')' > >
14 """
15
16 def transform(self, node, results):
17 syms = self.syms
18 exc, val, trc = (results[u"exc"], results[u"val"], results[u"trc"])
19 val = val[0] if val else Leaf(token.NAME, u"None")
20 val.prefix = trc.prefix = u" "
21 kids = [exc.clone(), Comma(), val.clone(), Comma(), trc.clone()]
22 args = results[u"args"]
23 args.children = kids