Implement noconvert for std::filesystem::path
Description
The current cast implementation for std::filesystem::path is to always cast. If the argument is marked as noconvert() it will convert regardless. This change rejects the argument if convert is false and the argument is not an instance of pathlib.Path.
Suggested changelog entry:
- Implement noconvert() for std::filesystem::path.
We should be checking for __fspath__, not isinstance Path.
We should be checking for
__fspath__, not isinstance Path.
I am confused about the intended implementation of noconvert
Should a noconvert argument accept any object that can be losslessly converted?
If that is the case the current implementation is correct but the type hint is incorrect.
Currently the type hints look like this
m.def("path_convert", [](std::filesystem::path) { }, py::arg("path"));
m.def("path_noconvert", [](std::filesystem::path) { }, py::arg("path").noconvert());
def path_convert(path: os.PathLike | str | bytes) -> None: ...
def path_noconvert(path: pathlib.Path) -> None: ...
I was modifying the type caster to match the type hint thinking that the type hint was correct.
Should the noconvert type hint be os.PathLike?
If that is the case I think io_name is insufficient to represent this.