GH-77609: Add follow_symlinks argument to pathlib.Path.glob()
by barneygale · Pull Request #102616 · python/cpython (original) (raw)
I don't want to add ***
. I think we can live without that.
I think the behaviour of path parts before any wildcard are easily assumed to be equivalent of being part of the base path. That is:
>>> Path("a1/b2").glob("c3/**")
# is the same as
>>> Path("a1/b2/c3").glob("**")
Everything from the first wildcard becomes a match pattern. We need to recurse deep enough to create paths with the same number of segments, and then match all the candidates against the pattern. Since we're now recursing, choosing not to follow symlinks by default is justifiable.
Given the current behaviour is to follow "spam*"
but not **
(that is, it's inconsistent), choosing one or the other feels more like a bugfix. I think we can describe it as "directory symlinks matched by using a wildcard will only be followed if the flag is set", whereas currently it depends on context, and a symlink may or may not be followed.
I'm pretty much leaning towards needing a deprecation period though. I think that'll be safest, and probably necessary, so the best way to do that is to support =None
for the option right now and plan to change it to False
in 3.14. Then we can show a deprecation warning when it's used. Hopefully there's a fairly separate way to implement the mixed behaviour that makes it easy to see what to remove later on.