Skip to content

Commit d4db526

Browse files
committed
Merge pull request #76 from brettcannon/fix_file_open
Have fix_open handle file()
2 parents c3cd373 + e4801e9 commit d4db526

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

libmodernize/fixes/fix_open.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
import libmodernize
55

66

7-
class FixOpen(fixer_base.ConditionalFix):
7+
class FixOpen(fixer_base.BaseFix):
88

99
BM_compatible = True
10-
order = "pre"
11-
skip_on = "io.open"
12-
10+
# Fixers don't directly stack, so make sure the 'file' case is covered.
1311
PATTERN = """
14-
power< 'open' trailer< '(' any+ ')' > >
12+
power< ('open' | 'file') trailer< '(' any+ ')' > >
1513
"""
1614

1715
def transform(self, node, results):
18-
if self.should_skip(node):
19-
return
2016
libmodernize.touch_import(u'io', u'open', node)

tests/test_fix_open.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
OPEN = ("""\
7-
open('some/path')
7+
{0}('some/path')
88
""", """\
99
from __future__ import absolute_import
1010
from io import open
@@ -13,7 +13,13 @@
1313

1414

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

1819
def test_open_optional():
19-
check_on_input(OPEN[0], OPEN[0])
20+
check_on_input(OPEN[0].format('open'), OPEN[0].format('open'))
21+
22+
def test_file():
23+
flags = ['-f', 'libmodernize.fixes.fix_open',
24+
'-f', 'libmodernize.fixes.fix_file']
25+
check_on_input(OPEN[0].format('file'), OPEN[1], extra_flags=flags)

0 commit comments

Comments
 (0)