File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change 4
4
import libmodernize
5
5
6
6
7
- class FixOpen (fixer_base .ConditionalFix ):
7
+ class FixOpen (fixer_base .BaseFix ):
8
8
9
9
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.
13
11
PATTERN = """
14
- power< 'open' trailer< '(' any+ ')' > >
12
+ power< ( 'open' | 'file') trailer< '(' any+ ')' > >
15
13
"""
16
14
17
15
def transform (self , node , results ):
18
- if self .should_skip (node ):
19
- return
20
16
libmodernize .touch_import (u'io' , u'open' , node )
Original file line number Diff line number Diff line change 4
4
5
5
6
6
OPEN = ("""\
7
- open ('some/path')
7
+ {0} ('some/path')
8
8
""" , """\
9
9
from __future__ import absolute_import
10
10
from io import open
13
13
14
14
15
15
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' ])
17
18
18
19
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 )
You can’t perform that action at this time.
0 commit comments