-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Labels
Description
Bug report
Bug description:
Prerequisites
Hello! I have a structure of directories as follows:
% tree
.
└── a
└── b
└── c
└── d
└── e
Problem
Here Pathlib.PurePath
a/b/c/d/e
won't match with **/b/c/**
, but will match with **/c/d/**
:
Python 3.12.3 (main, Apr 9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib
>>> path = pathlib.PurePath("a/b/c/d/e")
>>> path.match("**/b/c/**")
False
>>> path.match("**/c/d/**")
True
However, glob
on this structure yields different results:
>>> import glob
>>> glob.glob("**/b/c/**")
['a/b/c/d']
>>> glob.glob("**/c/d/**")
[]
>>> glob.glob("**/b/c/**", recursive=True)
['a/b/c/', 'a/b/c/d', 'a/b/c/d/e']
>>> glob.glob("**/c/d/**", recursive=True)
['a/b/c/d/', 'a/b/c/d/e']
i.e. **/b/c/**
and **/c/d/**
will match to the named path only in recursive mode.
Ideas
I'd expect pathlib.match to behave more like recursive glob.glob
(as in prior code block) or pathlib.Path.glob
:
>>> sorted(pathlib.Path(".").glob("**/b/c/**"))
[PosixPath('a/b/c'), PosixPath('a/b/c/d'), PosixPath('a/b/c/d/e')]
>>> sorted(pathlib.Path(".").glob("**/c/d/**"))
[PosixPath('a/b/c/d'), PosixPath('a/b/c/d/e')]
CPython versions tested on:
3.10, 3.12
Operating systems tested on:
Linux, macOS