Skip to content

Commit

Permalink
Merge pull request #76 from brettcannon/fix_file_open
Browse files Browse the repository at this point in the history
Have fix_open handle file()
  • Loading branch information
takluyver committed Sep 19, 2014
2 parents c3cd373 + e4801e9 commit d4db526
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 3 additions & 7 deletions libmodernize/fixes/fix_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
import libmodernize


class FixOpen(fixer_base.ConditionalFix):
class FixOpen(fixer_base.BaseFix):

BM_compatible = True
order = "pre"
skip_on = "io.open"

# Fixers don't directly stack, so make sure the 'file' case is covered.
PATTERN = """
power< 'open' trailer< '(' any+ ')' > >
power< ('open' | 'file') trailer< '(' any+ ')' > >
"""

def transform(self, node, results):
if self.should_skip(node):
return
libmodernize.touch_import(u'io', u'open', node)
12 changes: 9 additions & 3 deletions tests/test_fix_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


OPEN = ("""\
open('some/path')
{0}('some/path')
""", """\
from __future__ import absolute_import
from io import open
Expand All @@ -13,7 +13,13 @@


def test_open():
check_on_input(*OPEN, extra_flags=['-f', 'libmodernize.fixes.fix_open'])
check_on_input(OPEN[0].format('open'), OPEN[1],
extra_flags=['-f', 'libmodernize.fixes.fix_open'])

def test_open_optional():
check_on_input(OPEN[0], OPEN[0])
check_on_input(OPEN[0].format('open'), OPEN[0].format('open'))

def test_file():
flags = ['-f', 'libmodernize.fixes.fix_open',
'-f', 'libmodernize.fixes.fix_file']
check_on_input(OPEN[0].format('file'), OPEN[1], extra_flags=flags)

0 comments on commit d4db526

Please sign in to comment.