Skip to content

Make trio.Path.full_match synchronous - #3547

Open
ybai08 wants to merge 1 commit into
python-trio:mainfrom
ybai08:fix-path-full-match
Open

ybai08 wants to merge 1 commit into
python-trio:mainfrom
ybai08:fix-path-full-match

Conversation

@ybai08

@ybai08 ybai08 commented Oct 17, 2026

Copy link
Copy Markdown

pathlib.PurePath.full_match() (added in Python 3.13) only works on the path string, the same way match() does. But trio.Path wraps it with _wrap_method(pathlib.Path.full_match), so on 3.13+ it runs in a worker thread and gives back a coroutine:

>>> trio.Path("a.txt").full_match("*.py")
<coroutine object PurePath.full_match at 0x...>
>>> bool(_)
True

So if path.full_match(pattern): is always true, and Python warns that the coroutine was never awaited. trio.Path.match() and the other pure methods are inherited from PurePath and stay synchronous. The wrapper came in with the 3.13 bring-up in #3005. Running mypy --python-version 3.14 on src/trio/_path.py also reports it: the override's Awaitable[bool] doesn't match PurePath.full_match returning bool. CI runs mypy at 3.10, so CI doesn't hit that check.

This removes the wrapper, so trio.Path uses the inherited PurePath.full_match. If any code does await path.full_match(...), it will now fail with TypeError: object bool can't be used in 'await' expression. The newsfragment is filed as bugfix. I'm happy to change it to breaking if you'd rather.

Test: test_full_match_is_sync in src/trio/_tests/test_path.py. It is skipped below 3.13.

What was run locally (macOS arm64)
  • Python 3.14.7: pytest src/trio/_tests/test_path.py. Before the fix, test_full_match_is_sync fails with assert <coroutine object PurePath.full_match at ...> is True. After the fix: 40 passed, 1 skipped.
  • Python 3.13.15: test_path.py 40 passed, 1 skipped. Python 3.12.14: 39 passed, 2 skipped (the new test is skipped).
  • Full pytest src/trio on 3.14: 823 passed, 73 skipped, 3 xfailed (main: 822 passed, 73 skipped, 3 xfailed).
  • mypy --platform linux --python-version 3.14 src/trio/_path.py src/trio/_tests/test_path.py: clean. On main the same command reports the full_match override error.
  • mypy --platform {linux,darwin,win32} src/trio (config python_version 3.10, run from a 3.14 venv): 28 errors in 5 unrelated files, the same set as on main. None are in the changed files.
  • pytest --run-slow src/trio/_tests/test_exports.py: 8 failures, the same 8 as on main (pyright --verifytypes and jedi __notes__, both from the local environment). The mypy class-member checks pass.
  • black --check and ruff check on the changed files: clean.
  • Not run: the tox -e typing / type_completeness envs, Windows, Linux, PyPy.

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.
@ybai08
ybai08 force-pushed the fix-path-full-match branch from 70c69be to 5bdd013 Compare October 17, 2026 17:28
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00000%. Comparing base (4630d02) to head (5bdd013).

Additional details and impacted files
@@               Coverage Diff               @@
##                 main        #3547   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files             128          128           
  Lines           19474        19480    +6     
  Branches         1323         1323           
===============================================
+ Hits            19474        19480    +6     
Files with missing lines Coverage Δ
src/trio/_path.py 100.00000% <ø> (ø)
src/trio/_tests/test_path.py 100.00000% <100.00000%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant