msgspec
msgspec copied to clipboard
Support for pathlib.Path
Description
Sorry if this exists somewhere else. I did not find it.
It would be excellent if there was native support for pathlib.Path. Especially when reading YAML and TOML config files, paths seems like a common enough use case that it should have native support.
msgspec.ValidationError: Expected `Path`, got `str` - at `$.tls.cert`
def _dec_hook(type: Type, obj: Any) -> Any:
if type is PathLike:
return Path(obj).absolute()
return obj
In the long run this is a type I'd like to support builtin, but I'd like to do so after we refactor the extension mechanisms so support doesn't need to be handled as part of the C extension. Is using a dec_hook/enc_hook for these types insufficient for now?
my 2 cents: if support is coming, it should be using as_posix() which would work across *nix/Win
Is using a dec_hook/enc_hook for these types insufficient for now?
Not insufficient. Just seemingly unnecessary.
Looking forward to the refractor. If you need any help, happy to be pointed in the right direction to participate.