◐ Shell
clean mode source ↗

Message 362934 - Python tracker

A problem of having this bit of state in paths is that it violates assumptions based on immutability/hashability, e.g. with

    from pathlib import Path

    p = Path("foo")
    q = Path("foo")

    with p: pass

    unique_paths = {p, q}

    print(len(unique_paths))  # == 1, as p == q
    for path in unique_paths:
        print(path.resolve())  # Fails if the path is closed.

The last line fails with `unique_paths = {p, q}` as p has been closed (and apparently sets keep the first element when multiple "equal" elements are passed in), but not with `unique_paths = {q, p}`.

It would also prevent optimizations based on immutability as proposed in https://bugs.python.org/issue39783.