Repository: psf/black
File: src/black/__init__.py (Python)

Code before:
                and first_child.type == token.STRING
                and child.children[1].type == token.NEWLINE
            ):
                continue

            break

        elif first_child.type == syms.import_from:
            module_name = first_child.children[1]
            if not isinstance(module_name, Leaf) or module_name.value != "__future__":
                break

            imports |= set(get_imports_from_children(first_child.children[3:]))
        else:
            break

    return imports


def _is_diff_from_string_quote_types(diff: str) -> bool:
    """
    Returns True if the diff contains only changes in strings where quotes change from
    ' -> " or " -> '. For example

    -                    'desc["status"]=',  # str
    +                    "desc['status']=",  # str

    would match.
    """
    diff_lines = [line for line in diff.split("\n") if line and line[0] in ["-", "+"]][
        2:
    ]
    if all(line.endswith("# str") for line in diff_lines):
        # All differences are in strings
        prefixes = [line[0] for line in diff_lines]
        if all(prefix == "-" for prefix in prefixes[::2]) and all(
            prefix == "+" for prefix in prefixes[1::2]
        ):
            # We have an even pair of -/+ changes
            minus_concat = "".join([line[1:] for line in diff_lines[::2]])
            plus_concat = "".join([line[1:] for line in diff_lines[1::2]])
            if all(
                m == p or (m == "'" and p == '"') or (m == '"' and p == "'")
                for m, p in zip(minus_concat, plus_concat)
            ):
                # The only differences are quotes changing to other quotes
                return True
    return False


def assert_equivalent(src: str, dst: str) -> None:

Review comment (bug):
I don't think we should do this, as it changes visible output (due to the debug f-string). It's unlikely that people rely on that, sure, but I really don't want running Black to affect the output of a program.

Code after:
            features.add(Feature.ANN_ASSIGN_EXTENDED_RHS)

        elif (
            n.type == syms.with_stmt
            and len(n.children) > 2
            and n.children[1].type == syms.atom
        ):
            atom_children = n.children[1].children
            if (
                len(atom_children) == 3
                and atom_children[0].type == token.LPAR
                and atom_children[1].type == syms.testlist_gexp
                and atom_children[2].type == token.RPAR
            ):
                features.add(Feature.PARENTHESIZED_CONTEXT_MANAGERS)

        elif n.type == syms.match_stmt:
            features.add(Feature.PATTERN_MATCHING)

        elif (
            n.type == syms.except_clause
            and len(n.children) >= 2
            and n.children[1].type == token.STAR
        ):
            features.add(Feature.EXCEPT_STAR)

        elif n.type in {syms.subscriptlist, syms.trailer} and any(
            child.type == syms.star_expr for child in n.children
        ):
            features.add(Feature.VARIADIC_GENERICS)

        elif (
            n.type == syms.tname_star
            and len(n.children) == 3
            and n.children[2].type == syms.star_expr
        ):
            features.add(Feature.VARIADIC_GENERICS)

        elif n.type in (syms.type_stmt, syms.typeparams):
            features.add(Feature.TYPE_PARAMS)

    return features


def detect_target_versions(
    node: Node, *, future_imports: Optional[Set[str]] = None
) -> Set[TargetVersion]:
    """Detect the version to target based on the nodes used."""
    features = get_features_used(node, future_imports=future_imports)
    return {
        version for version in TargetVersion if features <= VERSION_TO_FEATURES[version]