Skip to content

Add missing keyword-only arguments to anyio.Path methods - #1286

Merged
agronholm merged 4 commits into
agronholm:masterfrom
jaideeppyne:path-kwarg-parity
Aug 21, 2026
Merged

agronholm merged 4 commits into
agronholm:masterfrom
jaideeppyne:path-kwarg-parity

Conversation

@jaideeppyne

Copy link
Copy Markdown
Contributor

Changes

anyio.Path aims to be a drop-in async mirror of pathlib.Path, but a few keyword-only arguments that CPython added in recent versions were missing, so passing them raised TypeError. This adds them, gated by sys.version_info so older interpreters keep the exact original signatures:

Method Argument Added in stdlib
exists() follow_symlinks Python 3.12
is_dir() follow_symlinks Python 3.13
is_file() follow_symlinks Python 3.13
read_text() newline Python 3.13

Before this change, on Python 3.13:

>>> await anyio.Path("link").is_file(follow_symlinks=False)
TypeError: Path.is_file() got an unexpected keyword argument 'follow_symlinks'

The new keyword arguments are forwarded to the underlying pathlib.Path call (via partial/run_sync), so the semantics match the standard library exactly.

Tests

Added regression tests in tests/test_fileio.py covering each new argument, each guarded with the appropriate skipif(sys.version_info < ...). They fail on master (with TypeError) and pass with this change. The existing test_fileio.py suite continues to pass, and ruff check, ruff format, and mypy are clean.

A changelog entry has been added under UNRELEASED.


🤖 This PR was prepared with the assistance of Claude Code.

Mirror the newer stdlib pathlib.Path signatures:
- exists(follow_symlinks=...) on Python 3.12+
- is_dir(follow_symlinks=...) / is_file(follow_symlinks=...) on Python 3.13+
- read_text(newline=...) on Python 3.13+

These were previously rejected with TypeError, breaking drop-in parity
with pathlib.Path. Gated by sys.version_info so older interpreters keep
the original signatures.

@agronholm agronholm left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@agronholm
agronholm merged commit 660a06d into agronholm:master Aug 21, 2026
20 checks passed
jaideeppyne added a commit to jaideeppyne/anyio that referenced this pull request Aug 25, 2026
agronholm pushed a commit that referenced this pull request Aug 25, 2026
The standard library gained a keyword-only ``follow_symlinks`` argument on ``pathlib.Path.owner()`` and ``pathlib.Path.group()`` in Python 3.13, but ``anyio.Path`` did not expose it, so passing the argument raised ``TypeError``. This is the same class of parity gap fixed in #1286, which covered exists()/is_dir()/is_file()/read_text() but missed owner()/group().
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.

2 participants