- cattrs version: 0.9.0
- Python version: 3.7
- Operating System: Win
Description
I am trying to serialize a class with a pathlib.Path object
What I Did
from pathlib import Path
import attr
@attr.s
class PathTest():
my_path: Path = attr.ib(default=Path('c:/test'))
cattr.structure({'my_path': 'c:/my_filepath',}, PathTest)
Error:
ValueError: Unsupported type: <class 'pathlib.Path'>. Register a structure hook for it.
The fix is easy, but I really feel like this is a fundamental type and should be supported out of the box
cattr.register_structure_hook(Path, lambda d, t: Path(d))
cattr.register_unstructure_hook(Path, lambda d: str(d))
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