Skip to content

test_ls_contrast is broken on Python 3.13 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jeremyschlatter opened this issue May 19, 2025 · 3 comments · Fixed by #5
Closed

test_ls_contrast is broken on Python 3.13 #4

jeremyschlatter opened this issue May 19, 2025 · 3 comments · Fixed by #5

Comments

@jeremyschlatter
Copy link
Contributor

From the Python 3.13 release notes:

Path.glob() and rglob() now return files and directories when given a pattern that ends with “**”. Previously, only directories were returned. (Contributed by Barney Gale in gh-70303.)

test_ls_contrast enforces the previous behavior of returning only directories. Under Python 3.13, it fails as follows:

_____________________________________________________________________________________ test_ls_contrast _____________________________________________________________________________________

    def test_ls_contrast():
        """recursive list of directories in directory"""
        # setup
        d1 = to_path("d1")
        mkdir(d1)
        d1d1 = to_path("d1/d1")
        mkdir(d1d1)
        d1d2 = to_path("d1/d2")
        mkdir(d1d2)
        d1d1f1 = to_path("d1/d1/f1")
        touch(d1d1f1)
        d1d2f2 = to_path("d1/d2/f2")
        touch(d1d2f2)

        # run test
        paths = ls(d1, select="**")

        # check
>       assert set(str(f) for f in paths) == set(["d1", "d1/d1", "d1/d2"])
E       AssertionError: assert {'d1', 'd1/d1...', 'd1/d2/f2'} == {'d1', 'd1/d1', 'd1/d2'}
E
E         Extra items in the left set:
E         'd1/d2/f2'
E         'd1/d1/f1'
E         Use -v to get more diff

tests/test_ls.py:250: AssertionError
@jeremyschlatter
Copy link
Contributor Author

jeremyschlatter commented May 19, 2025

I see two reasonable ways of resolving this:

  1. Change or remove the test, matching shlib's ls behavior to pathlib's new glob behavior. PR here.
  2. Change the implementation to preserve the old behavior: when a path ends in /**, add a trailing slash. (Adding a trailing slash is the workaround that was recommended by pathlib.) PR here.

jeremyschlatter added a commit to jeremyschlatter/shlib that referenced this issue May 19, 2025
Python 3.13 changed the behavior of trailing `**` globs, which changed
the behavior of `ls(..., select='.../**')`. This commit preserves the
previous behavior.

Fixes KenKundert#4
jeremyschlatter added a commit to jeremyschlatter/shlib that referenced this issue May 19, 2025
@jeremyschlatter
Copy link
Contributor Author

@KenKundert I'm not sure which way you want to go with this, so I made two different PRs to resolve the failing test. If you want to match pathlib's behavior, which changed in Python 3.13, go with #5. If you want to preserve shlib's previous behavior regardless of the Python version, go with #6.

@KenKundert
Copy link
Owner

All done. Thanks Jeremy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants