mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #21351 -- Replaced memoize with Python's lru_cache.
Replaced the custom, untested memoize with a similar decorator from Python's 3.2 stdlib. Although some minor performance degradation (see ticket), it is expected that in the long run lru_cache will outperform memoize once it is implemented in C. Thanks to EvilDMP for the report and Baptiste Mispelon for the idea of replacing memoize with lru_cache.
This commit is contained in:
parent
6c5f5b9a41
commit
9b7455e918
13 changed files with 254 additions and 38 deletions
|
@ -4,6 +4,7 @@ import warnings
|
|||
from django.test import SimpleTestCase, RequestFactory, override_settings
|
||||
from django.utils import six, translation
|
||||
from django.utils.deprecation import RenameMethodsBase
|
||||
from django.utils.functional import memoize
|
||||
|
||||
|
||||
class RenameManagerMethods(RenameMethodsBase):
|
||||
|
@ -205,3 +206,18 @@ class DeprecatedChineseLanguageCodes(SimpleTestCase):
|
|||
"The use of the language code 'zh-tw' is deprecated. "
|
||||
"Please use the 'zh-hant' translation instead.",
|
||||
])
|
||||
|
||||
|
||||
class DeprecatingMemoizeTest(SimpleTestCase):
|
||||
def test_deprecated_memoize(self):
|
||||
"""
|
||||
Ensure the correct warning is raised when memoize is used.
|
||||
"""
|
||||
warnings.simplefilter('always')
|
||||
|
||||
with warnings.catch_warnings(record=True) as recorded:
|
||||
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.')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue