1 | n/a | """Fixer for __nonzero__ -> __bool__ methods.""" |
---|
2 | n/a | # Author: Collin Winter |
---|
3 | n/a | |
---|
4 | n/a | # Local imports |
---|
5 | n/a | from .. import fixer_base |
---|
6 | n/a | from ..fixer_util import Name |
---|
7 | n/a | |
---|
8 | n/a | class FixNonzero(fixer_base.BaseFix): |
---|
9 | n/a | BM_compatible = True |
---|
10 | n/a | PATTERN = """ |
---|
11 | n/a | classdef< 'class' any+ ':' |
---|
12 | n/a | suite< any* |
---|
13 | n/a | funcdef< 'def' name='__nonzero__' |
---|
14 | n/a | parameters< '(' NAME ')' > any+ > |
---|
15 | n/a | any* > > |
---|
16 | n/a | """ |
---|
17 | n/a | |
---|
18 | n/a | def transform(self, node, results): |
---|
19 | n/a | name = results["name"] |
---|
20 | n/a | new = Name("__bool__", prefix=name.prefix) |
---|
21 | n/a | name.replace(new) |
---|