fix_memoryview.py 551 B

123456789101112131415161718192021
  1. u"""
  2. Fixer for memoryview(s) -> buffer(s).
  3. Explicit because some memoryview methods are invalid on buffer objects.
  4. """
  5. from lib2to3 import fixer_base
  6. from lib2to3.fixer_util import Name
  7. class FixMemoryview(fixer_base.BaseFix):
  8. explicit = True # User must specify that they want this.
  9. PATTERN = u"""
  10. power< name='memoryview' trailer< '(' [any] ')' >
  11. rest=any* >
  12. """
  13. def transform(self, node, results):
  14. name = results[u"name"]
  15. name.replace(Name(u"buffer", prefix=name.prefix))