10000 Added missing Path properties from Python 3.13 (#740) · IBMZ-Linux-OSS-Python/anyio@0558fbb · GitHub
[go: up one dir, main page]

Skip to content

Commit 0558fbb

Browse files
authored
Added missing Path properties from Python 3.13 (agronholm#740)
Fixes agronholm#737.
1 parent 053e8f0 commit 0558fbb

File tree

4 files changed 8000

+46
-3
lines changed

4 files changed

+46
-3
lines changed

docs/versionhistory.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Version history
33

44
This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
55

6+
**UNRELEASED**
7+
8+
- Added support for the ``from_uri()``, ``full_match()``, ``parser`` methods/properties
9+
in ``anyio.Path``, newly added in Python 3.13
10+
611
**4.4.0**
712

813
- Added the ``BlockingPortalProvider`` class to aid with constructing synchronous

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extend-select = [
8787
"required-imports" = ["from __future__ import annotations"]
8888

8989
[tool.mypy]
90-
python_version = "3.12"
90+
python_version = "3.13"
9191
strict = true
9292
ignore_missing_imports = true
9393
disallow_any_generics = false

src/anyio/_core/_fileio.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,28 @@ def as_posix(self) -> str:
358358
def as_uri(self) -> str:
359359
return self._path.as_uri()
360360

361-
def match(self, path_pattern: str) -> bool:
362-
return self._path.match(path_pattern)
361+
if sys.version_info >= (3, 13):
362+
parser = pathlib.Path.parser # type: ignore[attr-defined]
363+
364+
@classmethod
365+
def from_uri(cls, uri: str) -> Path:
366+
return Path(pathlib.Path.from_uri(uri)) # type: ignore[attr-defined]
367+
368+
def full_match(
369+
self, path_pattern: str, *, case_sensitive: bool | None = None
370+
) -> bool:
371+
return self._path.full_match( # type: ignore[attr-defined]
372+
path_pattern, case_sensitive=case_sensitive
373+
)
374+
375+
def match(
376+
self, path_pattern: str, *, case_sensitive: bool | None = None
377+
) -> bool:
378+
return self._path.match(path_pattern, case_sensitive=case_sensitive)
379+
else:
380+
381+
def match(self, path_pattern: str) -> bool:
382+
return self._path.match(path_pattern)
363383

364384
def is_relative_to(self, other: str | PathLike[str]) -> bool:
365385
try:

tests/test_fileio.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ def test_as_uri(self) -> None:
186186
else:
187187
assert Path("/foo/bar").as_uri() == "file:///foo/bar"
188188

189+
@pytest.mark.skipif(
190+
sys.version_info < (3, 13),
191+
reason="Path.from_uri() is only available on Python 3.13+",
192+
)
193+
def test_from_uri(self) -> None:
194+
path = Path.from_uri("file:///foo/bar")
195+
assert isinstance(path, Path)
196+
assert path.as_uri() == "file:///foo/bar"
197+
189198
async def test_cwd(self) -> None:
190199
result = await Path.cwd()
191200
assert isinstance(result, Path)
@@ -269,6 +278,7 @@ async def test_is_mount(self) -> None:
269278
assert not await Path("/gfobj4ewiotj").is_mount()
270279
assert await Path("/").is_mount()
271280

281+
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
272282
def test_is_reserved(self) -> None:
273283
expected_result = platform.system() == "Windows"
274284
assert Path("nul").is_reserved() == expected_result
@@ -339,6 +349,14 @@ def test_joinpath(self) -> None:
339349
path = Path("/foo").joinpath("bar")
340350
assert path == Path("/foo/bar")
341351

352+
@pytest.mark.skipif(
353+
sys.version_info < (3, 13),
354+
reason="Path.full_match() is only available on Python 3.13+",
355+
)
356+
def test_fullmatch(self) -> None:
357+
assert Path("/foo/bar").full_match("/foo/*")
358+
assert not Path("/foo/bar").full_match("/baz/*")
359+
342360
def test_match(self) -> None:
343361
assert Path("/foo/bar").match("/foo/*")
344362
assert not Path("/foo/bar").match("/baz/*")

0 commit comments

Comments
 (0)
0