File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change
1
+ from libmodernize .fixes import fix_file
1
2
from lib2to3 import fixer_base
2
3
from lib2to3 .fixer_util import touch_import
3
4
4
5
5
- class FixOpen (fixer_base . ConditionalFix ):
6
+ class FixOpen (fix_file . FixFile ):
6
7
7
8
BM_compatible = True
8
9
order = "pre"
9
- skip_on = "io.open"
10
10
11
11
PATTERN = """
12
- power< 'open' trailer< '(' any+ ')' > >
12
+ power< name=( 'open'|'file') trailer< '(' any+ ')' > any* >
13
13
"""
14
14
15
15
def transform (self , node , results ):
16
- if self .should_skip (node ):
17
- return
18
16
touch_import (u'io' , u'open' , node )
17
+ if len (results ['name' ]) == 1 and results ['name' ][0 ].value == 'file' :
18
+ results ['name' ] = results ['name' ][0 ]
19
+ super (FixOpen , self ).transform (node , results )
Original file line number Diff line number Diff line change 8
8
open('some/path')
9
9
""" )
10
10
11
+ FILE = ("""\
12
+ file('some/path')
13
+ """ , """\
14
+ from io import open
15
+ open('some/path')
16
+ """ )
17
+
11
18
12
19
def test_open ():
13
20
check_on_input (* OPEN , extra_flags = ['-f' , 'libmodernize.fixes.fix_open' ])
14
21
15
22
def test_open_optional ():
16
23
check_on_input (OPEN [0 ], OPEN [0 ])
24
+
25
+ def test_file ():
26
+ check_on_input (* FILE , extra_flags = ['-f' , 'libmodernize.fixes.fix_open' ])
You can’t perform that action at this time.
0 commit comments