Skip to content

Non idempotent input #2518

@nipunn1313

Description

@nipunn1313

Describe the bug

Non-idempotent source

To Reproduce

assert sort_by_dependency(
    {
        "1": {"2", "3"}, "2": {"2a", "2b"}, "3": {"3a", "3b"},
        "2a": set(), "2b": set(), "3a": set(), "3b": set()
    }
) == ["2a", "2b", "2", "3a", "3b", "3", "1"]

Run

black mytest.py
touch mytest.py
black --check mytest.py

Expected behavior

Second call to black shouldn't find changes to the code, but it does

** Actual behavior **

First call formats to

assert sort_by_dependency(
    {
        "1": {"2", "3"},
        "2": {"2a", "2b"},
        "3": {"3a", "3b"},
        "2a": set(),
        "2b": set(),
        "3a": set(),
        "3b": set(),
    }
) == ["2a", "2b", "2", "3a", "3b", "3", "1"]

Second call formats to

assert (
    sort_by_dependency(
        {
            "1": {"2", "3"},
            "2": {"2a", "2b"},
            "3": {"3a", "3b"},
            "2a": set(),
            "2b": set(),
            "3a": set(),
            "3b": set(),
        }
    )
    == ["2a", "2b", "2", "3a", "3b", "3", "1"]
)

Environment (please complete the following information):

  • Version: black, version 21.9b0
  • OS and Python version: mac - Python 3.9.7

Does this bug also happen on main?

Yep - just confirmed

Additional context

may be possible to minimize the test case, but haven't tried too much

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions