File tree Expand file tree Collapse file tree 2 files changed +11
-19
lines changed Expand file tree Collapse file tree 2 files changed +11
-19
lines changed Original file line number Diff line number Diff line change 1
- from libmodernize .fixes import fix_file
2
1
from lib2to3 import fixer_base
3
2
from lib2to3 .fixer_util import touch_import
4
3
5
4
6
- class FixOpen (fix_file . FixFile ):
5
+ class FixOpen (fixer_base . BaseFix ):
7
6
7
+ run_order = 10 # Must run after fix_file.
8
8
BM_compatible = True
9
- order = "pre"
10
-
9
+ # Fixers don't directly stack, so make sure the 'file' case is covered.
11
10
PATTERN = """
12
- power< name= ('open'| 'file') trailer< '(' any+ ')' > any* >
11
+ power< ('open' | 'file') trailer< '(' any+ ')' > >
13
12
"""
14
13
15
14
def transform (self , node , results ):
16
15
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 2
2
3
3
4
4
OPEN = ("""\
5
- open('some/path')
6
- """ , """\
7
- from io import open
8
- open('some/path')
9
- """ )
10
-
11
- FILE = ("""\
12
- file('some/path')
5
+ {0}('some/path')
13
6
""" , """\
14
7
from io import open
15
8
open('some/path')
16
9
""" )
17
10
18
11
19
12
def test_open ():
20
- check_on_input (* OPEN , extra_flags = ['-f' , 'libmodernize.fixes.fix_open' ])
13
+ check_on_input (OPEN [0 ].format ('open' ), OPEN [1 ],
14
+ extra_flags = ['-f' , 'libmodernize.fixes.fix_open' ])
21
15
22
16
def test_open_optional ():
23
- check_on_input (OPEN [0 ], OPEN [0 ])
17
+ check_on_input (OPEN [0 ]. format ( 'open' ) , OPEN [0 ]. format ( 'open' ) )
24
18
25
19
def test_file ():
26
- check_on_input (* FILE , extra_flags = ['-f' , 'libmodernize.fixes.fix_open' ])
20
+ flags = ['-f' , 'libmodernize.fixes.fix_open' ,
21
+ '-f' , 'libmodernize.fixes.fix_file' ]
22
+ check_on_input (OPEN [0 ].format ('file' ), OPEN [1 ], extra_flags = flags )
You can’t perform that action at this time.
0 commit comments