Package: landuo
landuo (cachedproperty)just a property but lazier...Simply put,cachedproperty=property+cached_property.Version: 1.0.0Reasons for Creating ThisIn-builtpropertydecorator allows you to manage your instances' attributes but at a cost of repeated computation for each read of the attribute.cached_propertybuilt by many [1], allows you to cache your instances' attributes but at a cost of losing the ability to implementsettermethods of them.cachedproperty(used interchangably withcached propertyor its variants) solves this problem by caching of the values of your instances' attributes AND implementingsettermethods for each of them.ObjectivesObjectiveDescriptionStatusBackward compatibilityIt should be 'easy' (ideally, by adding a one-liner) to existing project to incorporate caching in property.CachingProperty must be cached. It should allow the use of another 'cache' beyond the instance's__dict__attribute for instances whose__dict__attribute is a non-mutable mapping. Readmore.Kinda?Setter method is availableCached property should allow for the implementation of.setter(self, value)method.Deleter method is availableCached property should allow for the implementation of.deleter(self)method.Async compatibilityCached property should be thread-safe. pydanny'scached_propertyallows for this.No plans to do that in near future.Properties should be inherited as it is.An example would be best here, ifself.namereturnsself._namefor a superclass, then for the subclassself.nameshould still returnself._name, UNLESS wilfully overridden, e.g.self.namereturnsf'Hi, I'm {super().name}, the subclass' managed attributenameprepends'Hi, I'm '.InstallationMore on InstallationUsingpipWithpipinstalled, you can use the following command to installlanduo.python -m pip install landuoCheck thatlanduois installed by importing it in a python console.Example:fromlanduoimportproperty>>> property
<class 'landuo._lpusedict.BaseMutableCachedProperty'> # OutputHow to UseMore on UsageFor Existing ProjectIf you have an existing project which already uses the python's inbuiltproperty,addlanduoto your dependencies,add the following declaration into the import declarations in your modules that use the python's inbuiltproperty.fromlanduoimportproperty#... other import statementsThat's it! All your originalpropertyshould now have caching. By default, the cache used is the instance's attribute__dict__, read more atAPIs: cachedproperty.GlossaryManaged Attribute(s) - The set of attribute(s) of a class which is managed by thecachedproperty/propertyobject. To 'manage' means that the 'read' and/or 'write' capabilities of the attribute is decided by another python object.Private Variable(s) - Python has no strictly 'private' variable. In this case, the 'private' variable refers to the attribute of a class that is managed by another python object.Example:classPerson:def__init__(self,name):self._name=name# self._name is referred as the 'private' variable@property# `property` manages `self.name` and its underlying private variable is `self._name`defname(self):returnself._nameReferences[1] Here is a list of implementations for 'cached_property'.functools'cached_propertypydanny'scached_propertypenguinolog'scached_propertywerkzeug'scached_propertybottles'cached_propertybottles'lazy_attributesad2project'sLazyPropertyWhy the Namelanduo?懒惰 (Hàn yǔ Pīn yīn: lănduò) means lazy in Chinese, which describes thecachedpropertyclass of this package.