Title: glob.glob handling of * (asterisk) wildcard is broken
Type: enhancement Stage:
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Isaac Muse, docs@python, max0x7ba, nailor, petri.lehtinen, serhiy.storchaka
Priority: normal Keywords:

Created on 2021-06-10 15:53 by max0x7ba, last changed 2021-06-10 16:33 by max0x7ba.

Messages (5)
msg395545 - (view) Author: Maxim Egorushkin (max0x7ba) Date: 2021-06-10 15:53

`glob.glob` documentation states that "pathname ... can contain shell-style wildcards." 

However, it stops short of saying that shell-style wildcards are handled the same way as in a POSIX-compliant/friendly shell. POSIX requires that "`*` (asterisk) is a pattern that shall match any string, including the null string."

However, `glob.glob` pattern `*` (asterisk) doesn't match an empty/null string. 


$ ls *.bash_profile
$ python3 -c 'import glob; print(glob.glob("*.bash_profile"))'
$ python3 -c 'import glob; print(glob.glob(".bash_profile"))'
msg395547 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-06-10 16:17
Only pattern beginning with a dot can match filename beginning with a dot.


   Note that unlike fnmatch.fnmatch(), glob treats filenames beginning with a dot (.) as special cases.

This phrase was added in issue16695 in attempt to improve documentation, but it is still not clear.
msg395548 - (view) Author: Maxim Egorushkin (max0x7ba) Date: 2021-06-10 16:22
I may be naive, but why then:

$ python3 -c 'from pathlib import Path; print(list(Path(".").glob("*.bash_profile")))'



msg395550 - (view) Author: Isaac Muse (Isaac Muse) Date: 2021-06-10 16:31
Sadly, this because pathlib glob and glob.glob use different implementations. And glob.glob does not provide something equivalent to a DOTALL flag allowing a user to glob hidden files without explicitly defining the leading dot in the pattern.
msg395551 - (view) Author: Maxim Egorushkin (max0x7ba) Date: 2021-06-10 16:33
> glob.glob does not provide something equivalent to a DOTALL flag 

I see now, said a blind man.
Date User Action Args
2021-06-10 16:33:19max0x7basetmessages: + msg395551
2021-06-10 16:31:12Isaac Musesetnosy: + Isaac Muse
messages: + msg395550
2021-06-10 16:22:49max0x7basetmessages: + msg395548
2021-06-10 16:18:21serhiy.storchakasetnosy: + nailor, petri.lehtinen
2021-06-10 16:17:18serhiy.storchakasetassignee: docs@python
type: behavior -> enhancement
components: + Documentation, - Library (Lib)
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 3.8
nosy: + docs@python, serhiy.storchaka

messages: + msg395547
2021-06-10 16:00:25max0x7basettype: behavior
2021-06-10 15:53:43max0x7bacreate