-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from rowillia/add_unichr_fixer
Add a fixer for instances of `unichr`
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import absolute_import | ||
|
||
from lib2to3 import fixer_base | ||
from lib2to3.fixer_util import is_probably_builtin | ||
|
||
import libmodernize | ||
|
||
|
||
class FixUnichr(fixer_base.ConditionalFix): | ||
BM_compatible = True | ||
|
||
skip_on = 'six.moves.unichr' | ||
PATTERN = """'unichr'""" | ||
|
||
def transform(self, node, results): | ||
if self.should_skip(node): | ||
return | ||
if is_probably_builtin(node): | ||
libmodernize.touch_import(u'six', u'unichr', node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from __future__ import absolute_import | ||
|
||
from utils import check_on_input | ||
|
||
|
||
UNICHR_METHOD_REF = ("""\ | ||
converter = unichr | ||
""", """\ | ||
from __future__ import absolute_import | ||
from six import unichr | ||
converter = unichr | ||
""") | ||
|
||
UNICHR_METHOD_CALL = ("""\ | ||
unichr(42) | ||
""", """\ | ||
from __future__ import absolute_import | ||
from six import unichr | ||
unichr(42) | ||
""") | ||
|
||
UNICHR_USER_CALL = ("""\ | ||
foobar.unichr(42) | ||
""", """\ | ||
foobar.unichr(42) | ||
""") | ||
|
||
|
||
def test_unichr_method_ref(): | ||
check_on_input(*UNICHR_METHOD_REF) | ||
|
||
|
||
def test_unichr_method_call(): | ||
check_on_input(*UNICHR_METHOD_CALL) | ||
|
||
|
||
def test_unichr_user_call(): | ||
check_on_input(*UNICHR_USER_CALL) |