X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/ca9ad698ef75736828b644678eba2f4836db6277..2410213857d3cfb08a40350a9302b62d05df3c62:/black.py diff --git a/black.py b/black.py index 31e629b..680b1f4 100644 --- a/black.py +++ b/black.py @@ -49,7 +49,7 @@ from blib2to3.pgen2.grammar import Grammar from blib2to3.pgen2.parse import ParseError -__version__ = "18.9b0" +__version__ = "19.3b0" DEFAULT_LINE_LENGTH = 88 DEFAULT_EXCLUDES = ( r"/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist)/" @@ -246,6 +246,16 @@ def read_pyproject_toml( "per-file auto-detection]" ), ) +@click.option( + "--py36", + is_flag=True, + help=( + "Allow using Python 3.6-only syntax on all input files. This will put " + "trailing commas in function signatures and calls also after *args and " + "**kwargs. Deprecated; use --target-version instead. " + "[default: per-file auto-detection]" + ), +) @click.option( "--pyi", is_flag=True, @@ -349,6 +359,7 @@ def main( diff: bool, fast: bool, pyi: bool, + py36: bool, skip_string_normalization: bool, quiet: bool, verbose: bool, @@ -360,7 +371,17 @@ def main( """The uncompromising code formatter.""" write_back = WriteBack.from_configuration(check=check, diff=diff) if target_version: - versions = set(target_version) + if py36: + err(f"Cannot use both --target-version and --py36") + ctx.exit(2) + else: + versions = set(target_version) + elif py36: + err( + "--py36 is deprecated and will be removed in a future version. " + "Use --target-version py36 instead." + ) + versions = PY36_VERSIONS else: # We'll autodetect later. versions = set() @@ -705,13 +726,13 @@ def get_grammars(target_versions: Set[TargetVersion]) -> List[Grammar]: if not target_versions: return GRAMMARS 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 [ pygram.python_grammar_no_print_statement_no_exec_statement, pygram.python_grammar_no_print_statement, ] 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: @@ -2185,7 +2206,7 @@ def split_line( # All splits failed, best effort split with no omits. # This mostly happens to multiline strings that are by definition # reported as not fitting a single line. - yield from right_hand_split(line, supports_trailing_commas) + yield from right_hand_split(line, line_length, supports_trailing_commas) if line.inside_brackets: split_funcs = [delimiter_split, standalone_comment_split, rhs]