Skip to content

Commit

Permalink
More copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche committed Aug 30, 2022
1 parent ac622c9 commit 3468f9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/cattrs/converters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import Counter
from collections.abc import MutableSet as AbcMutableSet
from copy import deepcopy
from dataclasses import Field
from enum import Enum
from functools import lru_cache
Expand Down Expand Up @@ -309,7 +310,8 @@ def _unstructure_enum(self, obj):
"""Convert an enum to its value."""
return obj.value

def _unstructure_identity(self, obj):
@staticmethod
def _unstructure_identity(obj):
"""Just pass it through."""
return obj

Expand Down Expand Up @@ -643,8 +645,8 @@ def copy(
else self.detailed_validation,
)

res._unstructure_func = self._unstructure_func.copy(res._unstructure_identity)
res._structure_func = self._structure_func.copy(BaseConverter._structure_error)
res._unstructure_func = deepcopy(self._unstructure_func)
res._structure_func = deepcopy(self._structure_func)

return res

Expand Down Expand Up @@ -905,8 +907,8 @@ def copy(
else self.detailed_validation,
)

res._unstructure_func = self._unstructure_func.copy(res._unstructure_identity)
res._structure_func = self._structure_func.copy(BaseConverter._structure_error)
res._unstructure_func = deepcopy(self._unstructure_func)
res._structure_func = deepcopy(self._structure_func)

return res

Expand Down
4 changes: 2 additions & 2 deletions src/cattrs/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def clear_cache(self):
self._direct_dispatch.clear()
self.dispatch.cache_clear()

def copy(self, fallback_func):
res = self.__class__(fallback_func)
def __deepcopy__(self, _):
res = self.__class__(None)
res._function_dispatch = deepcopy(self._function_dispatch)
res._single_dispatch = deepcopy(self._single_dispatch)
return res
Expand Down
1 change: 0 additions & 1 deletion tests/test_copy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections import OrderedDict
from copy import deepcopy
from re import S
from typing import Callable, Type

from attr import define
Expand Down

0 comments on commit 3468f9e

Please sign in to comment.