dynattr
Dynamic Attributes Mixin
Dynamic Attributes Mixin
To install this package, run one of the following:
# create conda environment
$ mamba env create -f env.yml
# update conda environment
$ mamba env update -n dynattr --file env.yml
pip install -e .
conda environment
$ conda activate dynattr
# make sure the dynattr package is installed in development mode
$ pip install -e .
# make changes under nbs/ directory
# ...
# compile to have changes apply to the dynattr package
$ nbdev_prepare
# publish to pypi
$ nbdev_pypi
# publish to conda
$ nbdev_conda --build_args '-c conda-forge'
$ nbdev_conda --mambabuild --build_args '-c conda-forge -c dsm-72'
Install latest from the GitHub repository:
$ pip install git+https://github.com/dsm-72/dynattr.git
or from conda
$ conda install -c dsm-72 dynattr
or from pypi
$ pip install dynattr
Documentation can be found hosted on GitHub repository pages. Additionally you can find package manager specific guidelines on conda and pypi respectively.
from atyp import StrQ
from typing import ClassVar
class Foo(DynamicAttributesMixin):
X: str = 'X'
x: str = 'X'
Z: ClassVar[str] = 'Z'
toinstname = lambda x: f'_{x}'
totypename = lambda x: x.upper()
def __init__(self, x: StrQ = None):
self.x = (x or self.x)
f, b = Foo(x='x'), Foo()
(f.x, f.X, f.Z), (b.x, b.X, b.Z), (Foo.x, Foo.X, Foo.Z, )
(('x', 'X', 'Z'), ('X', 'X', 'Z'), ('X', 'X', 'Z'))
f.getinstclsattr('x', toinstname=None, totypename=None)
'X'
Summary
Dynamic Attributes Mixin
Last Updated
Sep 9, 2023 at 20:21
License
Apache Software
Total Downloads
36
Supported Platforms
GitHub Repository
https://github.com/dsm-72/dynattrDocumentation
https://dsm-72.github.io/dynattr