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:
Bouke Haarsma 2013-11-01 21:15:41 +01:00 committed by Baptiste Mispelon
parent 6c5f5b9a41
commit 9b7455e918
13 changed files with 254 additions and 38 deletions

View file

@ -17,6 +17,7 @@ from django.test.utils import override_settings
from django.utils import six
from . import urlconf_outer, middleware, views
from .views import empty_view
resolve_test_data = (
@ -662,12 +663,20 @@ class ErroneousViewTests(TestCase):
class ViewLoadingTests(TestCase):
def test_view_loading(self):
self.assertEqual(get_callable('urlpatterns_reverse.views.empty_view'),
empty_view)
# passing a callable should return the callable
self.assertEqual(get_callable(empty_view), empty_view)
def test_exceptions(self):
# A missing view (identified by an AttributeError) should raise
# ViewDoesNotExist, ...
six.assertRaisesRegex(self, ViewDoesNotExist, ".*View does not exist in.*",
get_callable,
'urlpatterns_reverse.views.i_should_not_exist')
six.assertRaisesRegex(self, ViewDoesNotExist,
".*View does not exist in.*",
get_callable,
'urlpatterns_reverse.views.i_should_not_exist')
# ... but if the AttributeError is caused by something else don't
# swallow it.
self.assertRaises(AttributeError, get_callable,
'urlpatterns_reverse.views_broken.i_am_broken')
'urlpatterns_reverse.views_broken.i_am_broken')