Skip to content

Commit

Permalink
Merge pull request #651 from asottile/warn-py2
Browse files Browse the repository at this point in the history
warn that py2 mode will be going away
  • Loading branch information
asottile committed Jun 6, 2022
2 parents f028b3d + 38a8f8f commit 84bfee2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pyupgrade/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,12 @@ def main(argv: Sequence[str] | None = None) -> int:
)
args = parser.parse_args(argv)

if args.min_version < (3,):
print(
'WARNING: pyupgrade will default to --py3-plus in 3.x',
file=sys.stderr,
)

ret = 0
for filename in args.filenames:
ret |= _fix_file(filename, args)
Expand Down
10 changes: 9 additions & 1 deletion tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def f():
def test_main_changes_a_file(tmpdir, capsys):
f = tmpdir.join('f.py')
f.write('x = set((1, 2, 3))\n')
assert main((f.strpath,)) == 1
assert main((f.strpath, '--py3-plus')) == 1
out, err = capsys.readouterr()
assert err == f'Rewriting {f.strpath}\n'
assert f.read() == 'x = {1, 2, 3}\n'
Expand Down Expand Up @@ -217,3 +217,11 @@ def test_main_stdin_with_changes(capsys):
assert main(('-',)) == 1
out, err = capsys.readouterr()
assert out == '{1, 2}\n'


def test_main_py27_mode_warning(capsys, tmpdir):
f = tmpdir.join('t.py').ensure()
assert not main((str(f),))
out, err = capsys.readouterr()
assert out == ''
assert err == 'WARNING: pyupgrade will default to --py3-plus in 3.x\n'

0 comments on commit 84bfee2

Please sign in to comment.