New submission from Isaac Muse <faceless.serv...@gmail.com>:

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.

----------
components: Library (Lib)
messages: 361259
nosy: Isaac Muse
priority: normal
severity: normal
status: open
title: Pathlib: handling of `.` in paths and patterns creates unmatchable paths
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39532>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to