projects
/
mdis.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
1309878
)
walker: support dataclasses
author
Dmitry Selyutin
<ghostmansd@gmail.com>
Sun, 18 Jun 2023 18:45:57 +0000
(21:45 +0300)
committer
Dmitry Selyutin
<ghostmansd@gmail.com>
Sun, 18 Jun 2023 18:46:23 +0000
(21:46 +0300)
src/mdis/walker.py
patch
|
blob
|
history
diff --git
a/src/mdis/walker.py
b/src/mdis/walker.py
index 5de9ff0e6055487802fe2b464ad020461d52b0c4..a5762fadd096a8a57f55af2f00b63366ef830634 100644
(file)
--- a/
src/mdis/walker.py
+++ b/
src/mdis/walker.py
@@
-3,6
+3,8
@@
__all__ = [
"WalkerMeta",
]
+import dataclasses
+
from . import dispatcher
@@
-23,6
+25,14
@@
class Walker(dispatcher.Dispatcher, metaclass=WalkerMeta):
yield (key, value)
yield from self((key, value))
+ @dispatcher.Hook(dataclasses.is_dataclass)
+ def dispatch_dataclass(self, instance):
+ for field in dataclasses.fields(instance):
+ key = field.name
+ value = getattr(instance, key)
+ yield (key, value)
+ yield from self((key, value))
+
@dispatcher.Hook(object)
def dispatch_object(self, instance):
yield from ()