classification
Title: Pathlib glob ** bug
Type: enhancement Stage: needs patch
Components: Documentation Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Andrew Dunai, Jon Walsh, Ronny.Pfannschmidt, christian.heimes, docs@python, pitrou, serhiy.storchaka, virtuald
Priority: normal Keywords:

Created on 2017-01-12 10:19 by Jon Walsh, last changed 2018-09-19 08:15 by Ronny.Pfannschmidt.

Messages (8)
msg285297 - (view) Author: Jon Walsh (Jon Walsh) Date: 2017-01-12 10:19
>>> from pathlib import Path
>>> Path("a/b/c/d/e.txt").match('a/*/**/*')
False
msg285305 - (view) Author: Andrew Dunai (Andrew Dunai) Date: 2017-01-12 11:11
Isn't this intended? According to https://docs.python.org/2/library/glob.html and wiki, typical UNIX glob pattern does not have the reqursive matching operator (`**`).
msg285308 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2017-01-12 11:20
The ticket is not about glob but about pathlib.

Pathlib supports ** directory globbing, but it's only documented as prefix globbing, https://docs.python.org/3/library/pathlib.html#pathlib.Path.glob
msg285311 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-01-12 11:32
** is supported not just as a prefix. Path('./Lib').glob('**/*.py') emits the same paths as Path('.').glob('Lib/**/*.py'). But ** is supported only in glob(), not in match(). The support of ** in match() is not documented. Would be worth to document explicitly that it is not supported.
msg285323 - (view) Author: Jon Walsh (Jon Walsh) Date: 2017-01-12 13:23
Seems a bit strange to not have glob() and match() working the same though. Is there any reason for that?
msg307854 - (view) Author: Dustin Spicuzza (virtuald) * Date: 2017-12-08 16:52
I just ran into this also. It seems like a very strange omission that match and glob don't support the same patterns (and I'm surprised that they don't share more code).
msg307866 - (view) Author: Dustin Spicuzza (virtuald) * Date: 2017-12-08 19:40
Because of backwards compatibility (despite a statement saying it's not guaranteed for pathlib), I think the best approach would be to create a 'globmatch' function for PurePath instead of modifying the match function, and document that the match function does a different kind of matching. 

This isn't a patch for cpython per se (ironically, don't have time for that this month...), but here's a MIT-licensed gist that patches pathlib2 and adds a globmatch function to it, plus associated tests extracted from pathlib2 and my own ** related tests. Works for me, feel free to do with it as you wish.

https://gist.github.com/virtuald/dd0373bf3f26ec0730adf1da0fb929bb
msg325735 - (view) Author: Ronny Pfannschmidt (Ronny.Pfannschmidt) Date: 2018-09-19 08:15
issue34731 was a duplicate of this

pytest was affected, as we port more bits to pathlib we hit this as well

bruno kindly implemented a local workaround in https://github.com/pytest-dev/pytest/pull/3980/files#diff-63fc5ed688925b327a5af20405bf4b09R19
History
Date User Action Args
2018-09-19 09:01:05berker.peksaglinkissue34731 superseder
2018-09-19 08:15:57Ronny.Pfannschmidtsetnosy: + Ronny.Pfannschmidt
messages: + msg325735
2017-12-08 19:40:12virtualdsetmessages: + msg307866
2017-12-08 16:52:14virtualdsetnosy: + virtuald
messages: + msg307854
2017-01-12 13:23:31Jon Walshsetmessages: + msg285323
2017-01-12 11:32:45serhiy.storchakasetassignee: docs@python
type: behavior -> enhancement
components: + Documentation, - Library (Lib)
versions: + Python 3.6, Python 3.7
nosy: + serhiy.storchaka, docs@python

messages: + msg285311
stage: needs patch
2017-01-12 11:29:12christian.heimessetnosy: + pitrou
2017-01-12 11:20:42christian.heimessetnosy: + christian.heimes
messages: + msg285308
2017-01-12 11:11:22Andrew Dunaisetnosy: + Andrew Dunai
messages: + msg285305
2017-01-12 10:19:54Jon Walshcreate