parent
026c81b834
commit
d6db1c12a8
4
black.py
4
black.py
@ -726,13 +726,13 @@ def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]:
|
|||||||
if not target_versions:
|
if not target_versions:
|
||||||
return GRAMMARS
|
return GRAMMARS
|
||||||
elif all(not version.is_python2() for version in target_versions):
|
elif all(not version.is_python2() for version in target_versions):
|
||||||
# Python 2-compatible code, so don't try Python 3 grammar.
|
# Python 3-compatible code, so don't try Python 2 grammar
|
||||||
return [
|
return [
|
||||||
pygram.python_grammar_no_print_statement_no_exec_statement,
|
pygram.python_grammar_no_print_statement_no_exec_statement,
|
||||||
pygram.python_grammar_no_print_statement,
|
pygram.python_grammar_no_print_statement,
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
return [pygram.python_grammar]
|
return [pygram.python_grammar_no_print_statement, pygram.python_grammar]
|
||||||
|
|
||||||
|
|
||||||
def lib2to3_parse(src_txt: str, target_versions: Iterable[TargetVersion] = ()) -> Node:
|
def lib2to3_parse(src_txt: str, target_versions: Iterable[TargetVersion] = ()) -> Node:
|
||||||
|
16
tests/data/python2_print_function.py
Executable file
16
tests/data/python2_print_function.py
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
print('hello')
|
||||||
|
print(u'hello')
|
||||||
|
print(a, file=sys.stderr)
|
||||||
|
|
||||||
|
# output
|
||||||
|
|
||||||
|
|
||||||
|
#!/usr/bin/env python2
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
print("hello")
|
||||||
|
print(u"hello")
|
||||||
|
print(a, file=sys.stderr)
|
@ -461,6 +461,14 @@ def test_python2(self) -> None:
|
|||||||
# black.assert_equivalent(source, actual)
|
# black.assert_equivalent(source, actual)
|
||||||
black.assert_stable(source, actual, black.FileMode())
|
black.assert_stable(source, actual, black.FileMode())
|
||||||
|
|
||||||
|
@patch("black.dump_to_file", dump_to_stderr)
|
||||||
|
def test_python2_print_function(self) -> None:
|
||||||
|
source, expected = read_data("python2_print_function")
|
||||||
|
mode = black.FileMode(target_versions={black.TargetVersion.PY27})
|
||||||
|
actual = fs(source, mode=mode)
|
||||||
|
self.assertFormatEqual(expected, actual)
|
||||||
|
black.assert_stable(source, actual, mode)
|
||||||
|
|
||||||
@patch("black.dump_to_file", dump_to_stderr)
|
@patch("black.dump_to_file", dump_to_stderr)
|
||||||
def test_python2_unicode_literals(self) -> None:
|
def test_python2_unicode_literals(self) -> None:
|
||||||
source, expected = read_data("python2_unicode_literals")
|
source, expected = read_data("python2_unicode_literals")
|
||||||
|
Loading…
Reference in New Issue
Block a user