-
-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for pathlib.Path #81
Comments
This would be very nice for GenConverter, I'd be willing to take a stab at implementing if this is deemed a good idea. I think it could be Edit: actually, most types don't have converters except for the preconfigured ones, maybe it wouldn't fit with the design? |
I'm not sure this is useful enough to be included by default, but a recipe in the Usages section of the docs would be cool! |
@Tinche , I just stumbled over this too. I think support for Pathlib would be very useful, because the way I understand it, pathlib is supposed to be a modern replacement for os.path. Oh and thx @spacemanspiff2007 for the fix. |
Two things:
More fundamentally, this approach is also how I think good software should be architected. As the OP rightly points out, adding support for |
I absolutely agree with you: However |
Alright, I consuled some other folks and I've changed my mind. Let's add this. |
Thank you, I really appreciate this! |
Awesome. I use BTW, cattr.register_unstructure_hook( Path, lambda d: str(d) ) "Cannot infer function type argument" Any suggested "fixes"? |
This is just a lack of lambda supports for type inference right? _convert_str: t.Callable[[t.Any], str] = lambda d: str(d)
cattr.register_unstructure_hook(Path, _convert_str) |
Yep, that works. I love the way Python is supposed to be pseudocode like and easy to read and understand 😉 🙄 My lazy workaround was: cattr.register_unstructure_hook( Path, lambda d: str(d) ) # type: ignore 🤣 |
Fixed on |
Description
I am trying to serialize a class with a pathlib.Path object
What I Did
Error:
The fix is easy, but I really feel like this is a fundamental type and should be supported out of the box
The text was updated successfully, but these errors were encountered: