6d316ac61999029ed9acd194e8f2a7bc41db5c3d
9 from . import dispatcher
12 class WalkerMeta(dispatcher
.DispatcherMeta
):
17 def __init__(self
, path
):
19 return super().__init
__()
22 return self
.__path
.__str
__()
25 return f
"{self.__class__.__name__}({str(self)})"
32 class IndexPath(GenericPath
):
34 return f
"[{self.path!r}]"
37 class AttributePath(GenericPath
):
39 return f
".{self.path}"
42 class HashPath(GenericPath
):
44 return f
"{{{self.path}}}"
47 class Walker(dispatcher
.Dispatcher
, metaclass
=WalkerMeta
):
48 @dispatcher.Hook(tuple, list)
49 def dispatch_ordered_sequence(self
, node
):
50 for (index
, item
) in enumerate(node
):
54 @dispatcher.Hook(set, frozenset)
55 def dispatch_unordered_sequence(self
, node
):
59 @dispatcher.Hook(dataclasses
.is_dataclass
)
60 def dispatch_dataclass(self
, node
):
61 for field
in dataclasses
.fields(node
):
63 value
= getattr(node
, key
)
67 @dispatcher.Hook(dict)
68 def dispatch_mapping(self
, node
):
69 for (key
, value
) in node
.items():
73 @dispatcher.Hook(object)
74 def dispatch_object(self
, node
):