From: George Sakkis Date: Sun, 19 Apr 2015 18:49:24 +0000 (+0300) Subject: lint (flake8) fixes X-Git-Tag: 1.2.0~5^2~8 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=33d39691649a7e96a07a37a2e91001135fde0b12;p=cached-property.git lint (flake8) fixes --- diff --git a/Makefile b/Makefile index 22ac8b8..2446d51 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ clean-pyc: find . -name '*~' -exec rm -f {} + lint: - flake8 cached_property tests + flake8 cached_property.py tests test: py.test diff --git a/cached_property.py b/cached_property.py index 48e615a..2d5d50c 100644 --- a/cached_property.py +++ b/cached_property.py @@ -10,11 +10,11 @@ import threading 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__') @@ -28,9 +28,11 @@ class cached_property(object): 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() @@ -48,10 +50,11 @@ class threaded_cached_property(cached_property): 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 @@ -97,9 +100,11 @@ timed_cached_property = cached_property_with_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() @@ -113,9 +118,9 @@ class threaded_cached_property_with_ttl(cached_property_with_ttl): 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 - diff --git a/tests/__init__.py b/tests/__init__.py index 7c68785..40a96af 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1 @@ -# -*- coding: utf-8 -*- \ No newline at end of file +# -*- coding: utf-8 -*- diff --git a/tests/test_cached_property.py b/tests/test_cached_property.py index bb40401..40a5ad9 100644 --- a/tests/test_cached_property.py +++ b/tests/test_cached_property.py @@ -88,8 +88,9 @@ class TestCachedProperty(unittest.TestCase): self.assertEqual(c.add_cached, None) def test_threads(self): - """ How well does the standard cached_property implementation work with threads? - Short answer: It doesn't! Use threaded_cached_property instead! + """ + How well does the standard cached_property implementation work with + threads? It doesn't, use threaded_cached_property instead! """ class Check(object): diff --git a/tests/test_cached_property_ttl.py b/tests/test_cached_property_ttl.py index 2470d60..5802516 100644 --- a/tests/test_cached_property_ttl.py +++ b/tests/test_cached_property_ttl.py @@ -7,8 +7,11 @@ test_threaded_cache_property.py 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, @@ -16,14 +19,6 @@ from cached_property import ( ) -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):