diff --git a/stdlib/@tests/test_cases/check_pathlib.py b/stdlib/@tests/test_cases/check_pathlib.py index 0b52c3669..9b4d681c9 100644 --- a/stdlib/@tests/test_cases/check_pathlib.py +++ b/stdlib/@tests/test_cases/check_pathlib.py @@ -1,6 +1,8 @@ from __future__ import annotations +import sys from pathlib import Path, PureWindowsPath +from typing_extensions import assert_type if Path("asdf") == Path("asdf"): ... @@ -18,3 +20,11 @@ if Path("asdf") == "asdf": # type: ignore # where they can never hold true. if PureWindowsPath("asdf") == Path("asdf"): # type: ignore ... + + +if sys.version_info >= (3, 13): + + class MyCustomPath(Path): ... + + pth = MyCustomPath.from_uri("file:///tmp/abc.txt") + assert_type(pth, MyCustomPath) diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index c8c8dde0f..dfa6648e7 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -113,7 +113,7 @@ class Path(PurePath): if sys.version_info >= (3, 13): @classmethod - def from_uri(cls, uri: str) -> Path: ... + def from_uri(cls, uri: str) -> Self: ... def is_dir(self, *, follow_symlinks: bool = True) -> bool: ... def is_file(self, *, follow_symlinks: bool = True) -> bool: ... def read_text(self, encoding: str | None = None, errors: str | None = None, newline: str | None = None) -> str: ...