From 39814eeb54ca37abbc0c6111504aa7d17984a5f7 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sat, 15 Sep 2007 10:57:03 +0000 Subject: [PATCH] Fixed #5487 -- Added deepcopying ability to lazy() objects, along with a test to demonstrate why the previous code failed. Debugging and patch from John Buchanan. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6276 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/functional.py | 7 +++++++ tests/regressiontests/forms/regressions.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/django/utils/functional.py b/django/utils/functional.py index 734704f6f3d..72a66917fc8 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -1,3 +1,5 @@ +import copy + def curry(_curried_func, *args, **kwargs): def _curried(*moreargs, **morekwargs): return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs)) @@ -101,6 +103,11 @@ def lazy(func, *resultclasses): else: raise AssertionError('__mod__ not supported for non-string types') + def __deepcopy__(self, memo): + result = copy.copy(self) + memo[id(self)] = result + return result + def __wrapper__(*args, **kw): # Creates the proxy object, instead of the actual value. return __proxy__(args, kw) diff --git a/tests/regressiontests/forms/regressions.py b/tests/regressiontests/forms/regressions.py index df2ef578a18..3212e201703 100644 --- a/tests/regressiontests/forms/regressions.py +++ b/tests/regressiontests/forms/regressions.py @@ -60,6 +60,12 @@ Translated error messages used to be buggy. u'\n

' >>> deactivate() +Deep copying translated text shouldn't raise an error +>>> from django.utils.translation import gettext_lazy +>>> class CopyForm(Form): +... degree = IntegerField(widget=Select(choices=((1, gettext_lazy('test')),))) +>>> f = CopyForm() + ####################### # Miscellaneous Tests # #######################