Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/libpasteurize/fixes/fix_annotations.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 to remove function annotations | |
| 3 """ | |
| 4 | |
| 5 from lib2to3 import fixer_base | |
| 6 from lib2to3.pgen2 import token | |
| 7 from lib2to3.fixer_util import syms | |
| 8 | |
| 9 warning_text = u"Removing function annotations completely." | |
| 10 | |
| 11 def param_without_annotations(node): | |
| 12 return node.children[0] | |
| 13 | |
| 14 class FixAnnotations(fixer_base.BaseFix): | |
| 15 | |
| 16 warned = False | |
| 17 | |
| 18 def warn_once(self, node, reason): | |
| 19 if not self.warned: | |
| 20 self.warned = True | |
| 21 self.warning(node, reason=reason) | |
| 22 | |
| 23 PATTERN = u""" | |
| 24 funcdef< 'def' any parameters< '(' [params=any] ')' > ['->' ret=any] ':' any* > | |
| 25 """ | |
| 26 | |
| 27 def transform(self, node, results): | |
| 28 u""" | |
| 29 This just strips annotations from the funcdef completely. | |
| 30 """ | |
| 31 params = results.get(u"params") | |
| 32 ret = results.get(u"ret") | |
| 33 if ret is not None: | |
| 34 assert ret.prev_sibling.type == token.RARROW, u"Invalid return annotation" | |
| 35 self.warn_once(node, reason=warning_text) | |
| 36 ret.prev_sibling.remove() | |
| 37 ret.remove() | |
| 38 if params is None: return | |
| 39 if params.type == syms.typedargslist: | |
| 40 # more than one param in a typedargslist | |
| 41 for param in params.children: | |
| 42 if param.type == syms.tname: | |
| 43 self.warn_once(node, reason=warning_text) | |
| 44 param.replace(param_without_annotations(param)) | |
| 45 elif params.type == syms.tname: | |
| 46 # one param | |
| 47 self.warn_once(node, reason=warning_text) | |
| 48 params.replace(param_without_annotations(params)) |
