mirror of
https://github.com/python/cpython.git
synced 2025-11-01 14:11:41 +00:00
Import lib2to3.
This commit is contained in:
parent
a4d77898db
commit
5e37baea80
68 changed files with 11993 additions and 0 deletions
23
Lib/lib2to3/fixes/fix_methodattrs.py
Normal file
23
Lib/lib2to3/fixes/fix_methodattrs.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
"""Fix bound method attributes (method.im_? -> method.__?__).
|
||||
"""
|
||||
# Author: Christian Heimes
|
||||
|
||||
# Local imports
|
||||
from . import basefix
|
||||
from .util import Name
|
||||
|
||||
MAP = {
|
||||
"im_func" : "__func__",
|
||||
"im_self" : "__self__",
|
||||
"im_class" : "__self__.__class__"
|
||||
}
|
||||
|
||||
class FixMethodattrs(basefix.BaseFix):
|
||||
PATTERN = """
|
||||
power< any+ trailer< '.' attr=('im_func' | 'im_self' | 'im_class') > any* >
|
||||
"""
|
||||
|
||||
def transform(self, node, results):
|
||||
attr = results["attr"][0]
|
||||
new = MAP[attr.value]
|
||||
attr.replace(Name(new, prefix=attr.get_prefix()))
|
||||
Loading…
Add table
Add a link
Reference in a new issue