Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/libpasteurize/fixes/fix_newstyle.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 "class Foo: ..." -> "class Foo(object): ..." | |
3 """ | |
4 | |
5 from lib2to3 import fixer_base | |
6 from lib2to3.fixer_util import LParen, RParen, Name | |
7 | |
8 from libfuturize.fixer_util import touch_import_top | |
9 | |
10 | |
11 def insert_object(node, idx): | |
12 node.insert_child(idx, RParen()) | |
13 node.insert_child(idx, Name(u"object")) | |
14 node.insert_child(idx, LParen()) | |
15 | |
16 class FixNewstyle(fixer_base.BaseFix): | |
17 | |
18 # Match: | |
19 # class Blah: | |
20 # and: | |
21 # class Blah(): | |
22 | |
23 PATTERN = u"classdef< 'class' NAME ['(' ')'] colon=':' any >" | |
24 | |
25 def transform(self, node, results): | |
26 colon = results[u"colon"] | |
27 idx = node.children.index(colon) | |
28 if (node.children[idx-2].value == '(' and | |
29 node.children[idx-1].value == ')'): | |
30 del node.children[idx-2:idx] | |
31 idx -= 2 | |
32 insert_object(node, idx) | |
33 touch_import_top(u'builtins', 'object', node) |