mirror of https://github.com/django/django.git
Removed django.utils.functional.memoize per deprecation timeline.
refs #21351.
This commit is contained in:
parent
9ce36512fa
commit
61ad1ea92b
|
@ -2,10 +2,8 @@ import copy
|
||||||
import operator
|
import operator
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
|
||||||
|
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.deprecation import RemovedInDjango19Warning
|
|
||||||
from django.utils.six.moves import copyreg
|
from django.utils.six.moves import copyreg
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,29 +16,6 @@ def curry(_curried_func, *args, **kwargs):
|
||||||
return _curried
|
return _curried
|
||||||
|
|
||||||
|
|
||||||
def memoize(func, cache, num_args):
|
|
||||||
"""
|
|
||||||
Wrap a function so that results for any argument tuple are stored in
|
|
||||||
'cache'. Note that the args to the function must be usable as dictionary
|
|
||||||
keys.
|
|
||||||
|
|
||||||
Only the first num_args are considered when creating the key.
|
|
||||||
"""
|
|
||||||
warnings.warn("memoize wrapper is deprecated and will be removed in "
|
|
||||||
"Django 1.9. Use django.utils.lru_cache instead.",
|
|
||||||
RemovedInDjango19Warning, stacklevel=2)
|
|
||||||
|
|
||||||
@wraps(func)
|
|
||||||
def wrapper(*args):
|
|
||||||
mem_args = args[:num_args]
|
|
||||||
if mem_args in cache:
|
|
||||||
return cache[mem_args]
|
|
||||||
result = func(*args)
|
|
||||||
cache[mem_args] = result
|
|
||||||
return result
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
class cached_property(object):
|
class cached_property(object):
|
||||||
"""
|
"""
|
||||||
Decorator that converts a method with a single self argument into a
|
Decorator that converts a method with a single self argument into a
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
from functools import wraps, update_wrapper
|
from functools import wraps, update_wrapper
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
import warnings
|
|
||||||
|
|
||||||
from django.contrib.admin.views.decorators import staff_member_required
|
from django.contrib.admin.views.decorators import staff_member_required
|
||||||
from django.contrib.auth.decorators import login_required, permission_required, user_passes_test
|
from django.contrib.auth.decorators import login_required, permission_required, user_passes_test
|
||||||
from django.http import HttpResponse, HttpRequest, HttpResponseNotAllowed
|
from django.http import HttpResponse, HttpRequest, HttpResponseNotAllowed
|
||||||
from django.middleware.clickjacking import XFrameOptionsMiddleware
|
from django.middleware.clickjacking import XFrameOptionsMiddleware
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.utils.functional import allow_lazy, lazy, memoize
|
from django.utils.functional import allow_lazy, lazy
|
||||||
from django.views.decorators.cache import cache_page, never_cache, cache_control
|
from django.views.decorators.cache import cache_page, never_cache, cache_control
|
||||||
from django.views.decorators.clickjacking import xframe_options_deny, xframe_options_sameorigin, xframe_options_exempt
|
from django.views.decorators.clickjacking import xframe_options_deny, xframe_options_sameorigin, xframe_options_exempt
|
||||||
from django.views.decorators.http import require_http_methods, require_GET, require_POST, require_safe, condition
|
from django.views.decorators.http import require_http_methods, require_GET, require_POST, require_safe, condition
|
||||||
|
@ -63,11 +62,6 @@ full_decorator = compose(
|
||||||
lazy,
|
lazy,
|
||||||
)
|
)
|
||||||
|
|
||||||
# suppress the deprecation warning of memoize
|
|
||||||
with warnings.catch_warnings():
|
|
||||||
warnings.filterwarnings('ignore')
|
|
||||||
fully_decorated = memoize(fully_decorated, {}, 1)
|
|
||||||
|
|
||||||
fully_decorated = full_decorator(fully_decorated)
|
fully_decorated = full_decorator(fully_decorated)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ from django.test.utils import reset_warning_registry
|
||||||
from django.utils import six, translation
|
from django.utils import six, translation
|
||||||
from django.utils.deprecation import RenameMethodsBase
|
from django.utils.deprecation import RenameMethodsBase
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.functional import memoize
|
|
||||||
|
|
||||||
|
|
||||||
class RenameManagerMethods(RenameMethodsBase):
|
class RenameManagerMethods(RenameMethodsBase):
|
||||||
|
@ -214,20 +213,6 @@ class DeprecatedChineseLanguageCodes(SimpleTestCase):
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
class DeprecatingMemoizeTest(SimpleTestCase):
|
|
||||||
def test_deprecated_memoize(self):
|
|
||||||
"""
|
|
||||||
Ensure the correct warning is raised when memoize is used.
|
|
||||||
"""
|
|
||||||
with warnings.catch_warnings(record=True) as recorded:
|
|
||||||
warnings.simplefilter('always')
|
|
||||||
memoize(lambda x: x, {}, 1)
|
|
||||||
msg = str(recorded.pop().message)
|
|
||||||
self.assertEqual(msg,
|
|
||||||
'memoize wrapper is deprecated and will be removed in Django '
|
|
||||||
'1.9. Use django.utils.lru_cache instead.')
|
|
||||||
|
|
||||||
|
|
||||||
class DeprecatingSimpleTestCaseUrls(unittest.TestCase):
|
class DeprecatingSimpleTestCaseUrls(unittest.TestCase):
|
||||||
|
|
||||||
def test_deprecation(self):
|
def test_deprecation(self):
|
||||||
|
|
Loading…
Reference in New Issue