class cached_property(object):
- """ A property that is only computed once per instance and then replaces
- itself with an ordinary attribute. Deleting the attribute resets the
- property.
- Source: https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76
- """
+ """
+ A property that is only computed once per instance and then replaces itself
+ with an ordinary attribute. Deleting the attribute resets the property.
+ Source: https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76
+ """ # noqa
def __init__(self, func):
self.__doc__ = getattr(func, '__doc__')
class threaded_cached_property(cached_property):
- """ A cached_property version for use in environments where multiple
- threads might concurrently try to access the property.
- """
+ """
+ A cached_property version for use in environments where multiple threads
+ might concurrently try to access the property.
+ """
+
def __init__(self, func):
super(threaded_cached_property, self).__init__(func)
self.lock = threading.RLock()
class cached_property_with_ttl(object):
- """ A property that is only computed once per instance and then replaces
- itself with an ordinary attribute. Setting the ttl to a number expresses
- how long the property will last before being timed out.
- """ # noqa
+ """
+ A property that is only computed once per instance and then replaces itself
+ with an ordinary attribute. Setting the ttl to a number expresses how long
+ the property will last before being timed out.
+ """
def __init__(self, ttl=None):
ttl_or_func = ttl
class threaded_cached_property_with_ttl(cached_property_with_ttl):
- """ A cached_property version for use in environments where multiple
- threads might concurrently try to access the property.
- """
+ """
+ A cached_property version for use in environments where multiple threads
+ might concurrently try to access the property.
+ """
+
def __init__(self, ttl=None):
super(threaded_cached_property_with_ttl, self).__init__(ttl)
self.lock = threading.RLock()
return obj._cache[prop_name][0]
# If not, do the calculation and release the lock.
- return super(threaded_cached_property_with_ttl, self).__get__(obj, cls)
+ return super(threaded_cached_property_with_ttl, self).__get__(obj,
+ cls)
# Alias to make threaded_cached_property_with_ttl easier to use
threaded_cached_property_ttl = threaded_cached_property_with_ttl
timed_threaded_cached_property = threaded_cached_property_with_ttl
-
Tests for `cached-property` module, cached_property_with_ttl.
Tests for `cached-property` module, threaded_cache_property_with_ttl.
"""
+
import unittest
from freezegun import freeze_time
+from time import sleep
+from threading import Lock, Thread
from cached_property import (
cached_property_with_ttl,
)
-from time import sleep
-from threading import Lock, Thread
-import unittest
-from freezegun import freeze_time
-
-from cached_property import cached_property
-
-
class TestCachedPropertyWithTTL(unittest.TestCase):
def test_cached_property(self):