Skip to content

Commit 214d9d2

Browse files
committed
fixed indentation in memoize
1 parent fa34384 commit 214d9d2

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

source/modules/Decorators.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,20 @@ function with given arguments:
222222
.. code-block:: python
223223
224224
class Memoize:
225-
"""
226-
memoize decorator from avinash.vora
227-
http://avinashv.net/2008/04/python-decorators-syntactic-sugar/
228-
"""
229-
def __init__(self, function): # runs when memoize class is called
230-
self.function = function
231-
self.memoized = {}
232-
233-
def __call__(self, *args): # runs when memoize instance is called
234-
try:
235-
return self.memoized[args]
236-
except KeyError:
237-
self.memoized[args] = self.function(*args)
238-
return self.memoized[args]
225+
"""
226+
memoize decorator from avinash.vora
227+
http://avinashv.net/2008/04/python-decorators-syntactic-sugar/
228+
"""
229+
def __init__(self, function): # runs when memoize class is called
230+
self.function = function
231+
self.memoized = {}
232+
233+
def __call__(self, *args): # runs when memoize instance is called
234+
try:
235+
return self.memoized[args]
236+
except KeyError:
237+
self.memoized[args] = self.function(*args)
238+
return self.memoized[args]
239239
240240
241241
Let's try that out with a potentially expensive function:
@@ -333,7 +333,7 @@ Add yet another function in scope:
333333
def decorator(arg1, arg2):
334334
def real_decorator(function):
335335
def wrapper(*args, **kwargs):
336-
print("Congratulations. You decorated a function that does
336+
print("Congratulations. You decorated a function that does
337337
something with {} and {}".format(arg1, arg2))
338338
function(*args, **kwargs)
339339
return wrapper

0 commit comments

Comments
 (0)