summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-05-13 15:10:34 +0200
committerAnton Khirnov <anton@khirnov.net>2021-05-13 15:10:34 +0200
commit954d79c47d4c123d1dafc2c670d79685b7ce84b1 (patch)
tree85032afabb7e5ba1f620c1b3bd7dd963be95ad84
parentfe6a3233800630c9ac6e6668f6eb048e8ab1d321 (diff)
utils/cached_property: replace with the stdlib implementation
-rw-r--r--alot/completion/command.py2
-rw-r--r--alot/utils/cached_property.py75
2 files changed, 1 insertions, 76 deletions
diff --git a/alot/completion/command.py b/alot/completion/command.py
index 72c82ea3..43ffcea2 100644
--- a/alot/completion/command.py
+++ b/alot/completion/command.py
@@ -2,12 +2,12 @@
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
+from functools import cached_property
import logging
from alot import commands
from alot.buffers import EnvelopeBuffer
from alot.settings.const import settings
-from alot.utils.cached_property import cached_property
from .completer import Completer
from .commandname import CommandNameCompleter
from .tag import TagCompleter
diff --git a/alot/utils/cached_property.py b/alot/utils/cached_property.py
deleted file mode 100644
index 3ad66413..00000000
--- a/alot/utils/cached_property.py
+++ /dev/null
@@ -1,75 +0,0 @@
-# verbatim from werkzeug.utils.cached_property
-#
-# Copyright (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following
-# disclaimer in the documentation and/or other materials provided
-# with the distribution.
-#
-# * The names of the contributors may not be used to endorse or
-# promote products derived from this software without specific
-# prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-_missing = object()
-
-
-class cached_property:
- """A decorator that converts a function into a lazy property. The
- function wrapped is called the first time to retrieve the result
- and then that calculated result is used the next time you access
- the value::
-
- class Foo:
-
- @cached_property
- def foo(self):
- # calculate something important here
- return 42
-
- The class has to have a `__dict__` in order for this property to
- work.
- """
-
- # implementation detail: this property is implemented as non-data
- # descriptor. non-data descriptors are only invoked if there is
- # no entry with the same name in the instance's __dict__.
- # this allows us to completely get rid of the access function call
- # overhead. If one choses to invoke __get__ by hand the property
- # will still work as expected because the lookup logic is replicated
- # in __get__ for manual invocation.
-
- def __init__(self, func, name=None, doc=None):
- self.__name__ = name or func.__name__
- self.__module__ = func.__module__
- self.__doc__ = doc or func.__doc__
- self.func = func
-
- def __get__(self, obj, type=None):
- if obj is None:
- return self
- value = obj.__dict__.get(self.__name__, _missing)
- if value is _missing:
- value = self.func(obj)
- obj.__dict__[self.__name__] = value
- return value