Overriding Field.deepcopy for RegexField by kchang · Pull Request #2617 · encode/django-rest-framework (original) (raw)
Hi there,
Wondering if there's been a decision made on this? I'm running into the same deepcopy issue with RegexFields.
Having regex
taken out of kwargs
def __init__(self, regex, **kwargs):
super(RegexField, self).__init__(**kwargs)
<..snip..>
doesn't seem to avoid them being in self._kwargs
def __new__(cls, *args, **kwargs):
"""
When a field is instantiated, we store the arguments that were used,
so that we can present a helpful representation of the object.
"""
<..snip..>
instance._kwargs = kwargs
return instance
and it's self._kwargs
that actually ends up being deepcopy()
ed in __deepcopy__
def __deepcopy__(self, memo):
"""
When cloning fields we instantiate using the arguments it was
originally created with, rather than copying the complete state.
"""
args = copy.deepcopy(self._args)
kwargs = dict(self._kwargs)
<..snip..>
kwargs = copy.deepcopy(kwargs)
<..snip..>