comparison env/lib/python3.7/site-packages/libpasteurize/fixes/fix_next.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
1 u"""
2 Fixer for:
3 it.__next__() -> it.next().
4 next(it) -> it.next().
5 """
6
7 from lib2to3.pgen2 import token
8 from lib2to3.pygram import python_symbols as syms
9 from lib2to3 import fixer_base
10 from lib2to3.fixer_util import Name, Call, find_binding, Attr
11
12 bind_warning = u"Calls to builtin next() possibly shadowed by global binding"
13
14
15 class FixNext(fixer_base.BaseFix):
16
17 PATTERN = u"""
18 power< base=any+ trailer< '.' attr='__next__' > any* >
19 |
20 power< head='next' trailer< '(' arg=any ')' > any* >
21 |
22 classdef< 'class' base=any+ ':'
23 suite< any*
24 funcdef< 'def'
25 attr='__next__'
26 parameters< '(' NAME ')' > any+ >
27 any* > >
28 """
29
30 def transform(self, node, results):
31 assert results
32
33 base = results.get(u"base")
34 attr = results.get(u"attr")
35 head = results.get(u"head")
36 arg_ = results.get(u"arg")
37 if arg_:
38 arg = arg_.clone()
39 head.replace(Attr(Name(unicode(arg),prefix=head.prefix),
40 Name(u"next")))
41 arg_.remove()
42 elif base:
43 attr.replace(Name(u"next", prefix=attr.prefix))