Skip to content

Commit 5bdd013

Browse files
committed
Make trio.Path.full_match synchronous
PurePath.full_match() is a pure path method like match(), but trio.Path wrapped it to run in a worker thread, so path.full_match(pattern) returned a coroutine (always truthy) instead of a bool. Drop the wrapper so the inherited PurePath implementation is used.
1 parent 4630d02 commit 5bdd013

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎newsfragments/3547.bugfix.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`trio.Path.full_match` is now a synchronous method, like `pathlib.PurePath.full_match` and `trio.Path.match`. It was previously wrapped to run in a worker thread, so calling it without ``await`` returned a coroutine, which is always truthy.

‎src/trio/_path.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ def __repr__(self) -> str:
260260
write_text = _wrap_method(pathlib.Path.write_text)
261261
if sys.version_info < (3, 12):
262262
link_to = _wrap_method(pathlib.Path.link_to)
263-
if sys.version_info >= (3, 13):
264-
full_match = _wrap_method(pathlib.Path.full_match)
265263

266264
def as_uri(self) -> str:
267265
return self._wrapped_cls(self).as_uri()

‎src/trio/_tests/test_path.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import pathlib
5+
import sys
56
from typing import TYPE_CHECKING
67

78
import pytest
@@ -230,6 +231,17 @@ async def test_globmethods(path: trio.Path) -> None:
230231
assert entries == {"_bar.txt", "bar.txt"}
231232

232233

234+
def test_full_match_is_sync() -> None:
235+
if sys.version_info < (3, 13):
236+
pytest.skip("PurePath.full_match is 3.13+")
237+
238+
# full_match() is a pure path method like match(), so it must not be async
239+
path = trio.Path("foo/bar.py")
240+
assert path.full_match("**/*.py") is True
241+
assert path.full_match("*.py") is False
242+
assert path.full_match("FOO/BAR.PY", case_sensitive=False) is True
243+
244+
233245
async def test_as_uri(path: trio.Path) -> None:
234246
path = await path.parent.resolve()
235247

0 commit comments

Comments
 (0)