Skip to content

Commit

Permalink
Fix magic/non-magic mix handling (#206)
Browse files Browse the repository at this point in the history
* Fix magic/non-magic mix handling

Fixes #205

* Fix mypy
  • Loading branch information
facelessuser committed Aug 30, 2023
1 parent 223f9ca commit 32c5a5b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions docs/src/markdown/about/changelog.md
@@ -1,5 +1,9 @@
# Changelog

## 8.5.1

- **FIX**: Fix handling of current directory when magic and non-magic patterns are mixed in `glob` pattern list.

## 8.5

- **NEW**: Formally support Python 3.11 (no change).
Expand Down
12 changes: 12 additions & 0 deletions tests/test_glob.py
Expand Up @@ -1000,6 +1000,18 @@ def test_negateall_bytes(self):
for file in glob.glob(b'!**/', flags=glob.N | glob.NEGATEALL | glob.G, root_dir=os.fsencode(self.tempdir)):
self.assert_equal(os.path.isdir(file), False)

def test_magic_non_magic(self):
"""Test logic when switching from magic to non-magic patterns."""

with change_cwd(self.tempdir):
self.assert_equal(sorted(glob.glob(['**/aab', 'dummy'], flags=glob.G)), ['aab',])

def test_non_magic_magic(self):
"""Test logic when switching from non-magic to magic patterns."""

with change_cwd(self.tempdir):
self.assert_equal(sorted(glob.glob(['dummy', '**/aab'], flags=glob.G)), ['aab',])


class TestGlobMarked(Testglob):
"""Test glob marked."""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_pathlib.py
Expand Up @@ -340,10 +340,10 @@ def test_pickle(self):
p3 = pickle.loads(pickle.dumps(p1))
p4 = pickle.loads(pickle.dumps(p2))

self.assertTrue(type(p1) == type(p3))
self.assertTrue(type(p2) == type(p4))
self.assertTrue(type(p1) != type(p2))
self.assertTrue(type(p3) != type(p4))
self.assertTrue(type(p1) == type(p3)) # noqa: E721
self.assertTrue(type(p2) == type(p4)) # noqa: E721
self.assertTrue(type(p1) != type(p2)) # noqa: E721
self.assertTrue(type(p3) != type(p4)) # noqa: E721


class TestExpansionLimit(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion wcmatch/__meta__.py
Expand Up @@ -194,5 +194,5 @@ def parse_version(ver: str) -> Version:
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(8, 5, 0, "final")
__version_info__ = Version(8, 5, 1, "final")
__version__ = __version_info__._get_canonical()
4 changes: 2 additions & 2 deletions wcmatch/glob.py
Expand Up @@ -795,9 +795,9 @@ def format_path(self, path: AnyStr, is_dir: bool, dir_only: bool) -> Iterator[An
def glob(self) -> Iterator[AnyStr]:
"""Starts off the glob iterator."""

curdir = self.current

for pattern in self.pattern:
curdir = self.current

# If the pattern ends with `/` we return the files ending with `/`.
dir_only = pattern[-1].dir_only if pattern else False
self.is_abs_pattern = pattern[0].is_drive if pattern else False
Expand Down
2 changes: 1 addition & 1 deletion wcmatch/pathlib.py
Expand Up @@ -113,7 +113,7 @@ def _translate_path(self) -> str:

return name + sep

def match(
def match( # type: ignore[override, unused-ignore]
self,
patterns: str | Sequence[str],
*,
Expand Down

0 comments on commit 32c5a5b

Please sign in to comment.