Skip to content

Instantly share code, notes, and snippets.

@flaviut
Created August 23, 2018 01:09
Show Gist options
  • Save flaviut/7088e5543b65b1dd1320a822c9cb2ef5 to your computer and use it in GitHub Desktop.
Save flaviut/7088e5543b65b1dd1320a822c9cb2ef5 to your computer and use it in GitHub Desktop.
from lib2to3 import fixer_base
from lib2to3.pytree import Node
from lib2to3.pygram import python_symbols as syms
from lib2to3.fixer_util import Name, ArgList
import libmodernize
class FixGetcwd(fixer_base.ConditionalFix):
BM_compatible = True
skip_on = "six.moves.getcwd"
PATTERN = """
power< 'os' trailer< dot='.' name='getcwdu' > any* >
"""
def transform(self, node, results):
new = Node(syms.power, [Name("getcwd"), ArgList([])], prefix="")
new.prefix = node.prefix
libmodernize.touch_import(u'six.moves', u'getcwd', node)
return new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment