mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-03 17:59:19 +02:00

- This renames deltachat.types to deltachat.props. Not re-using a stdlib name is somewhat nice and solves a weird edge-case for me where the deltachat.types module can be hiding stdlib types by the deltachat directory appearing before the stlib on sys.path. - When manually invoking the build script (rather then via pip/setup.py) it figures out where the package actually lives and makes sure the .so file ends up in that directory. This is better than the current version which depends on the current directory and thus sometimes creates an alternate deltachat/ directory tree. - Add some common python artefact files to gitignore.
30 lines
805 B
Python
30 lines
805 B
Python
"""Helpers for properties."""
|
|
|
|
|
|
def with_doc(f):
|
|
return property(f, None, None, f.__doc__)
|
|
|
|
|
|
# copied over unmodified from
|
|
# https://github.com/devpi/devpi/blob/master/common/devpi_common/types.py
|
|
def cached(f):
|
|
"""returns a cached property that is calculated by function f"""
|
|
def get(self):
|
|
try:
|
|
return self._property_cache[f]
|
|
except AttributeError:
|
|
self._property_cache = {}
|
|
except KeyError:
|
|
pass
|
|
x = self._property_cache[f] = f(self)
|
|
return x
|
|
|
|
def set(self, val):
|
|
propcache = self.__dict__.setdefault("_property_cache", {})
|
|
propcache[f] = val
|
|
|
|
def fdel(self):
|
|
propcache = self.__dict__.setdefault("_property_cache", {})
|
|
del propcache[f]
|
|
|
|
return property(get, set, fdel)
|