From 2ffc65fed472fe80687ab126ad9d380af48bf40c Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 10 Sep 2021 09:54:54 +0200 Subject: [PATCH] Remove trailing system path separator from pattern Shell completion often adds a separator '/' after directory names. Because os.walk() return paths without a trailing separator, we have to remove trailing separators from patterns to ensure a proper match. Granted, we could attempt to remove the trailing separator '/' only from "directory patterns", not from "file patterns", but patterns are currently just patterns - we do not distinguish between "file patterns" and "directory patterns". A future improvment could be to interpret a pattern with a trailing "/" as "directory pattern", but then how would we define a "file pattern"? It's probably better to find a different mechanism and keep discarding the trailing separator from patterns. --- codespell_lib/_codespell.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 49a62a3996a..43b747e659a 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -139,8 +139,14 @@ class GlobMatch: def __init__(self, pattern: Optional[str]) -> None: self.pattern_list: Optional[List[str]] if pattern: - # Pattern might be a list of comma-delimited strings - self.pattern_list = ",".join(pattern).split(",") + self.pattern_list = [ + # We remove trailing path separators from each pattern + # because shell completion might add a trailing separator + # '/' after directory names + p.rstrip(os.path.sep) + # Pattern might be a list of comma-separated patterns + for p in ",".join(pattern).split(",") + ] else: self.pattern_list = None