1 | n/a | """Fix bound method attributes (method.im_? -> method.__?__). |
---|
2 | n/a | """ |
---|
3 | n/a | # Author: Christian Heimes |
---|
4 | n/a | |
---|
5 | n/a | # Local imports |
---|
6 | n/a | from .. import fixer_base |
---|
7 | n/a | from ..fixer_util import Name |
---|
8 | n/a | |
---|
9 | n/a | MAP = { |
---|
10 | n/a | "im_func" : "__func__", |
---|
11 | n/a | "im_self" : "__self__", |
---|
12 | n/a | "im_class" : "__self__.__class__" |
---|
13 | n/a | } |
---|
14 | n/a | |
---|
15 | n/a | class FixMethodattrs(fixer_base.BaseFix): |
---|
16 | n/a | BM_compatible = True |
---|
17 | n/a | PATTERN = """ |
---|
18 | n/a | power< any+ trailer< '.' attr=('im_func' | 'im_self' | 'im_class') > any* > |
---|
19 | n/a | """ |
---|
20 | n/a | |
---|
21 | n/a | def transform(self, node, results): |
---|
22 | n/a | attr = results["attr"][0] |
---|
23 | n/a | new = MAP[attr.value] |
---|
24 | n/a | attr.replace(Name(new, prefix=attr.prefix)) |
---|