This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Pathlib: handling of `.` in paths and patterns creates unmatchable paths
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Isaac Muse
Priority: normal Keywords:

Created on 2020-02-02 23:45 by Isaac Muse, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg361259 - (view) Author: Isaac Muse (Isaac Muse) Date: 2020-02-02 23:45
It appears that the pathlib library strips out `.` in glob paths when they represent a directory. This is kind of a naive approach in my opinion, but I understand what was trying to be achieved.

When a path is given to pathlib, it normalizes it by stripping out non-essential things like `.` that represent directories, and strips out trailing `/` to give a path without unnecessary parts (the stripping of trailing `/` is another discussion).

But there is a small twist, when given an empty string or just a dot, you need to have something as the directory, so it allows a `.`.

So, it appears the idea was since this normalization is applied to paths, why not apply it to the glob patterns as well, so it does. But the special logic that ensures you don't have an empty string to match does not get applied to the glob patterns. This creates unmatchable paths:

>>> import pathlib
>>> str(pathlib.Path('.'))
'.'
>>> pathlib.Path('.').match('.')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python36\lib\pathlib.py", line 939, in match
    raise ValueError("empty pattern")
ValueError: empty pattern

I wonder if it is appropriate to apply this `.` stripping to glob patterns. Personally, I think the glob pattern, except for slash normalization, should remain unchanged, but if it is to be normalized above and beyond this, at the very least should use the exact same logic that is applied to the paths.
msg361261 - (view) Author: Isaac Muse (Isaac Muse) Date: 2020-02-03 00:15
The more I think about this, I think the normalization of paths is actually fine, it is the normalization of the patterns that is problematic, or more the difference in normalization. I could live with the pattern normalization of `.` and trailing `/` if it was at least consistent with what happens in paths. I still find the modification of the glob pattern in this manner surprising, but at least it wouldn't' cause cases like this to fail.
History
Date User Action Args
2022-04-11 14:59:26adminsetgithub: 83713
2020-02-03 00:15:33Isaac Musesetmessages: + msg361261
2020-02-02 23:45:17Isaac Musecreate