Repository: facelessuser/wcmatch

Issue:
Order of magic and non-magic patterns breaks the glob result
Using mixed magic and non-magic patterns like
```python
# this_script.py
from wcmatch.glob import glob

patterns = ["**/this_script.py", "dummy"]

print(
    glob(patterns),
    glob(patterns[::-1])
)
```
I expect both results to contain the "this_script.py". If all the magic patterns are before others this works fine, otherwise the results are broken - in this case empty.

the culprit seems to be line https://github.com/facelessuser/wcmatch/blob/223f9caba2a4d9ce6b796d890693773e9c5d4080/wcmatch/glob.py#L810  The variable is overwritten in the loop, affecting the call to `_glob` later. 

Discussion:
facelessuser: @gir-bot lgtm

Patch:
diff --git a/docs/src/markdown/about/changelog.md b/docs/src/markdown/about/changelog.md
index 5ac87ee..75a29ab 100644
--- a/docs/src/markdown/about/changelog.md
+++ b/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).
diff --git a/wcmatch/__meta__.py b/wcmatch/__meta__.py
index 4f206d7..b53d065 100644
--- a/wcmatch/__meta__.py
+++ b/wcmatch/__meta__.py
@@ -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()
diff --git a/wcmatch/glob.py b/wcmatch/glob.py
index 313904e..ec6be54 100644
--- a/wcmatch/glob.py
+++ b/wcmatch/glob.py
@@ -795,9 +795,9 @@ class Glob(Generic[AnyStr]):
     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
diff --git a/wcmatch/pathlib.py b/wcmatch/pathlib.py
index 8632056..24e04ee 100644
--- a/wcmatch/pathlib.py
+++ b/wcmatch/pathlib.py
@@ -113,7 +113,7 @@ class PurePath(pathlib.PurePath):
 
         return name + sep
 
-    def match(
+    def match(  # type: ignore[override, unused-ignore]
         self,
         patterns: str | Sequence[str],
         *,


Test patch:
diff --git a/tests/test_glob.py b/tests/test_glob.py
index 57331f2..81c0918 100644
--- a/tests/test_glob.py
+++ b/tests/test_glob.py
@@ -1000,6 +1000,18 @@ class Testglob(_TestGlob):
         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."""
diff --git a/tests/test_pathlib.py b/tests/test_pathlib.py
index 5508056..9142e36 100644
--- a/tests/test_pathlib.py
+++ b/tests/test_pathlib.py
@@ -340,10 +340,10 @@ class TestComparisons(unittest.TestCase):
         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):