X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/866be066463fc8fd01c16559596641f6ead1e797..2227e6b1cdd301523ad8bde476a4afc0ba995f21:/black.py diff --git a/black.py b/black.py index 9494c4c..c96d205 100644 --- a/black.py +++ b/black.py @@ -3382,10 +3382,13 @@ class Report: def parse_ast(src: str) -> Union[ast3.AST, ast27.AST]: - try: - return ast3.parse(src) - except SyntaxError: - return ast27.parse(src) + for feature_version in (7, 6): + try: + return ast3.parse(src, feature_version=feature_version) + except SyntaxError: + continue + + return ast27.parse(src) def assert_equivalent(src: str, dst: str) -> None: @@ -3438,11 +3441,9 @@ def assert_equivalent(src: str, dst: str) -> None: try: src_ast = parse_ast(src) except Exception as exc: - major, minor = sys.version_info[:2] raise AssertionError( - f"cannot use --safe with this file; failed to parse source file " - f"with Python {major}.{minor}'s builtin AST. Re-run with --fast " - f"or stop using deprecated Python 2 syntax. AST error message: {exc}" + f"cannot use --safe with this file; failed to parse source file. " + f"AST error message: {exc}" ) try: