Skip to content

Commit 0faf9ee

Browse files
committed
fix bugs
1 parent 96a75cb commit 0faf9ee

File tree

4 files changed

+37
-35
lines changed

4 files changed

+37
-35
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Version][aucsvg]][auc] [![Supports Python][pythonsvg]][python] [![Build Status][travismaster]][travis] [![Repository][repositorysvg]][repository] [![License][licensesvg]][license]
44

5-
[aucsvg]: https://img.shields.io/badge/memoization-v0.0.9-brightgreen.svg
5+
[aucsvg]: https://img.shields.io/badge/memoization-v0.0.10-brightgreen.svg
66
[auc]: https://github.com/lonelyenvoy/python-memoization
77

88
[pythonsvg]: https://img.shields.io/badge/python-2.6,_2.7,_3.2,_3.3,_3.4,_3.5,_3.6,_3.7-brightgreen.svg

memoization/_undecorated.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

memoization/memoization.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import time
66
from functools import wraps
77
from functools import reduce
8-
from _undecorated import include_undecorated_function
98

10-
__version__ = '0.0.9'
9+
__version__ = '0.0.10'
1110
_cache = {}
1211

1312

@@ -22,7 +21,7 @@ def cached(max_items=None, ttl=None):
2221
If not given, the data in cache is valid forever.
2322
:return: decorator
2423
"""
25-
@include_undecorated_function()
24+
@_include_undecorated_function()
2625
def decorator(func):
2726
"""
2827
@cached decorator.
@@ -189,6 +188,38 @@ def _retrieve_safe_function_id(func):
189188
return function_id
190189

191190

191+
def _include_undecorated_function(key='original'):
192+
"""
193+
Decorator to include original function in a decorated one
194+
195+
e.g.
196+
@include_undecorated_function()
197+
def shout(f):
198+
def _():
199+
string = f()
200+
return string.upper()
201+
return _
202+
203+
204+
@shout
205+
def hello():
206+
return 'hello world'
207+
208+
print hello() # HELLO WORLD
209+
print hello.original() # hello world
210+
211+
:param key: The key to access the original function
212+
:return: decorator
213+
"""
214+
def this_decorator(decorator):
215+
def wrapper(func):
216+
decorated = decorator(func)
217+
setattr(decorated, key, func)
218+
return decorated
219+
return wrapper
220+
return this_decorator
221+
222+
192223
if __name__ == '__main__':
193224
import sys
194225
sys.stderr.write('python-memoization v' + __version__ +

memoization/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from setuptools import setup, find_packages
22

33
setup(name='memoization',
4-
version='0.0.9',
4+
version='0.0.10',
55
description='A minimalist functional caching lib for Python, with TTL and auto memory management support. '
66
'(https://github.com/lonelyenvoy/python-memoization)',
77
keywords='memoization memorization remember decorator cache caching function callable'
88
'functional ttl limited capacity fast high-performance optimization',
99
url='https://github.com/lonelyenvoy/python-memoization',
1010
author='lonelyenvoy',
1111
author_email='petrinchor@gmail.com',
12+
py_modules=['memoization'],
1213
license='MIT',
1314
packages=find_packages(),
1415
exclude_package_data={'': ['examples.py', 'test.py']})

0 commit comments

Comments
 (0)