-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-22276: Fix pathlib.Path.glob not to ignore trailing path separator #10349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed tests, the documentation update, a news and What's New entries.
And don't forget about an alternate separator on Windows.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
fdc8e41
to
187aaf0
Compare
I didn't expect the Spanish Inquisition. |
Nobody expects the Spanish Inquisition! @serhiy-storchaka: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to use sep
and altsep
(and corresponding pathlib attributes) instead of hardcoding '/'
in the general code.
Misc/NEWS.d/next/Library/2018-11-11-04-41-11.bpo-22276.Tt19TW.rst
Outdated
Show resolved
Hide resolved
187aaf0
to
dcae663
Compare
@serhiy-storchaka Thank you for your advice. |
BTW, I address bpo-33392 ( |
ping |
/cc @barneygale |
Hey @e-kwsm, sorry for the long wait. Are you still interested in working on this PR? If so I can help review. |
Yes. |
@e-kwsm The bot is broken and is being fixed so no worries. |
I don't think the code should make additional |
You can also press "Update branch" to trigger testing. |
I propose simpler patch: diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 4763ab54f6..a759db1684 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -281,7 +281,9 @@ def make_uri(self, path):
def _make_selector(pattern_parts, flavour):
pat = pattern_parts[0]
child_parts = pattern_parts[1:]
- if pat == '**':
+ if not pat:
+ return _TerminatingSelector()
+ elif pat == '**':
cls = _RecursiveWildcardSelector
elif '**' in pat:
raise ValueError("Invalid pattern: '**' can only be an entire path component")
@@ -943,6 +945,8 @@ def glob(self, pattern):
drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
if drv or root:
raise NotImplementedError("Non-relative patterns are unsupported")
+ if pattern[-1] in (self._flavour.sep, self._flavour.altsep):
+ pattern_parts.append('')
selector = _make_selector(tuple(pattern_parts), self._flavour)
for p in selector.select_from(self):
yield p
@@ -956,6 +960,8 @@ def rglob(self, pattern):
drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
if drv or root:
raise NotImplementedError("Non-relative patterns are unsupported")
+ if pattern[-1] in (self._flavour.sep, self._flavour.altsep):
+ pattern_parts.append('')
selector = _make_selector(("**",) + tuple(pattern_parts), self._flavour)
for p in selector.select_from(self):
yield p |
You're right, but I was also trying to get rid of the old CLA check. |
7c7f251
to
937b12a
Compare
@serhiy-storchaka Thank you for your review. I have reflected your suggestion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Misc/NEWS.d/next/Library/2018-11-11-04-41-11.bpo-22276.Tt19TW.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Serhiy Storchaka <[email protected]>
@e-kwsm would you mind signing our new digital CLA (see the "details" link in the failing status check)? |
Done. |
Thanks! |
See also Issue 33392: pathlib .glob('*/') returns files as well as directories, closed as duplicate of 22276.
At present
pathlib.Path.glob
returns directories and FILES even if glob pattern ends with the path separator (/
in Linux), whileglob.glob
works as expected.This PR fixes the behaviour.
https://bugs.python.org/issue22276