Closed danielnelson closed 1 year ago
I think the head of the handler pairs needs to be copied, because we prepend new hooks to the front, but we are currently copying the tail. Maybe a change along these lines:
diff --git a/src/cattrs/dispatch.py b/src/cattrs/dispatch.py
index f8a5445..c6542ea 100644
--- a/src/cattrs/dispatch.py
+++ b/src/cattrs/dispatch.py
@@ -137,4 +137,4 @@ class FunctionDispatch:
return len(self._handler_pairs)
def copy_to(self, other: "FunctionDispatch", skip: int = 0):
- other._handler_pairs.extend(self._handler_pairs[skip:])
+ other._handler_pairs = self._handler_pairs[:-skip] + other._handler_pairs
Yeah you're right. The tests only test copying of singledispatch hooks, oops. Looking into it at https://github.com/python-attrs/cattrs/pull/399
Should be fixed on main, let me know!
Description
I wanted to create a base Converter with some common unstructuring hooks, then copy it in other places and add extra hooks. After copying the Converter I found that the unstructuring hooks from the source Converter no longer work.
What I Did