Skip to content

Commit

Permalink
Changed Path to pathlib.Path for compatibility with pybind11-stubgen
Browse files Browse the repository at this point in the history
  • Loading branch information
timohl committed Jan 5, 2025
1 parent 2a7dda2 commit 9d0766c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/pybind11/stl/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct path_caster {
return true;
}

PYBIND11_TYPE_CASTER(T, io_name("Union[os.PathLike, str, bytes]", "Path"));
PYBIND11_TYPE_CASTER(T, io_name("Union[os.PathLike, str, bytes]", "pathlib.Path"));
};

#endif // PYBIND11_HAS_FILESYSTEM || defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,19 @@ def __fspath__(self):
assert m.parent_path(PseudoBytesPath()) == Path("foo")
assert (
doc(m.parent_path)
== "parent_path(arg0: Union[os.PathLike, str, bytes]) -> Path"
== "parent_path(arg0: Union[os.PathLike, str, bytes]) -> pathlib.Path"
)
# std::vector
assert m.parent_paths(["foo/bar", "foo/baz"]) == [Path("foo"), Path("foo")]
assert (
doc(m.parent_paths)
== "parent_paths(arg0: list[Union[os.PathLike, str, bytes]]) -> list[Path]"
== "parent_paths(arg0: list[Union[os.PathLike, str, bytes]]) -> list[pathlib.Path]"
)
# py::typing::List
assert m.parent_paths_list(["foo/bar", "foo/baz"]) == [Path("foo"), Path("foo")]
assert (
doc(m.parent_paths_list)
== "parent_paths_list(arg0: list[Union[os.PathLike, str, bytes]]) -> list[Path]"
== "parent_paths_list(arg0: list[Union[os.PathLike, str, bytes]]) -> list[pathlib.Path]"
)
# Nested py::typing::List
assert m.parent_paths_nested_list([["foo/bar"], ["foo/baz", "foo/buzz"]]) == [
Expand All @@ -286,13 +286,13 @@ def __fspath__(self):
]
assert (
doc(m.parent_paths_nested_list)
== "parent_paths_nested_list(arg0: list[list[Union[os.PathLike, str, bytes]]]) -> list[list[Path]]"
== "parent_paths_nested_list(arg0: list[list[Union[os.PathLike, str, bytes]]]) -> list[list[pathlib.Path]]"
)
# py::typing::Tuple
assert m.parent_paths_tuple(("foo/bar", "foo/baz")) == (Path("foo"), Path("foo"))
assert (
doc(m.parent_paths_tuple)
== "parent_paths_tuple(arg0: tuple[Union[os.PathLike, str, bytes], Union[os.PathLike, str, bytes]]) -> tuple[Path, Path]"
== "parent_paths_tuple(arg0: tuple[Union[os.PathLike, str, bytes], Union[os.PathLike, str, bytes]]) -> tuple[pathlib.Path, pathlib.Path]"
)
# py::typing::Dict
assert m.parent_paths_dict(
Expand All @@ -308,7 +308,7 @@ def __fspath__(self):
}
assert (
doc(m.parent_paths_dict)
== "parent_paths_dict(arg0: dict[str, Union[os.PathLike, str, bytes]]) -> dict[str, Path]"
== "parent_paths_dict(arg0: dict[str, Union[os.PathLike, str, bytes]]) -> dict[str, pathlib.Path]"
)


Expand Down

0 comments on commit 9d0766c

Please sign in to comment.