Lazy properties and attributes for sidekick.
Project description
Functions in this module are helpers intended to create convenient and declarative idioms when declaring classes. Perhaps it is not entirely correct calling them “functional”, but since some patterns such as lazy properties are common in functional libraries, Sidekick has a module for doing that.
This library can be installed independently from the rest of sidekick distribution using pip install sidekick-properties. Prefer depending on sidekick-properties if your project only use those functions.
Quick start
from typing import NamedTuple
from sidekick.properties import lazy, alias, delegate_to # or from sidekick.api import *
class Person(NamedTuple):
name: str
age: int
full_name = alias('name')
p = Person('Karl Heinrich', age=29)
Now p.full_name is now an alias to p.name. This usage simply exposes an attribute under a different name. func:alias can be configured in many different ways by choosing mutability and simple transformations between the exposed alias and the original attribute.
class Employee(NamedTuple):
person: Person
role: str
name = delegate_to('person')
age = delegate_to('person')
@lazy
def photo(self):
return download_from_server(f'http://url.img/employees/{self.name}')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file sidekick-properties-0.1.0.tar.gz
.
File metadata
- Download URL: sidekick-properties-0.1.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.0 importlib_metadata/3.7.2 packaging/20.9 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 059a9b2c0679155f44adf2499bc1e444542bab7bedd86dbdcf03c2da57bf43e2 |
|
MD5 | 995433019ca7b8f84468a748d8775089 |
|
BLAKE2b-256 | ff7487e2d9431b8d96234d3a3ce373ef75f31929310fbdfaf898e37a14f84851 |