A fully typed Ref(...) object to reference a value, with runtime typechecking.
Project description
Reference Container
This library implements a simple container which holds a single value. The container is completely typed, supports an optional default value, supports readonly mode, and does runtime type checking.
Examples
from refcontainer import Ref, ReadOnlyError
# Initialize with value
str_ref = Ref('hello')
assert str_ref.current == 'hello'
del str_ref.current
_ = str_ref.current # raises AttributeError
str_ref.current = 'world'
assert str_ref.current == 'world'
str_ref.current = 0 # raises TypeError
str_ref.engrave('hello')
str_ref.current = 'world' # raises ReadOnlyError
# Initialize as readonly (engraved)
str_ref = Ref.readonly('hello')
del str_ref.current # raises ReadOnlyError
assert str_ref.current == 'hello'
# Initialize with type tags
ref = Ref[str | int]('hello')
assert ref.current == 'hello'
ref.current = 'world'
ref.current = 0
with raises(TypeError):
ref.current = 0.
# Disable type checking
ref = Ref[Any]('hello')
# Initialize with type but without value
num_ref = Ref[float]()
with raises(AttributeError):
_ = num_ref.current
num_ref.current = 0.
assert num_ref.current == 0
num_ref.current = 'hello' # raises TypeError
Installation
From PyPI:
pip install refcontainer
From source:
git clone git@github.com:balintmaci/python-ref.git
cd python-ref
pip install .
Use
-ewith install to link sources to installation
Build:
python -m build .
Push to PyPI:
python3 -m twine upload --repository pypi dist/*
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file refcontainer-0.0.3.tar.gz.
File metadata
- Download URL: refcontainer-0.0.3.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bb3d3a932da42253c85e7142cf5be03dde2d3a2eef10f1586c7889eb3056810
|
|
| MD5 |
fa7fed90d35d582e4024fadd224d295b
|
|
| BLAKE2b-256 |
0b4050f2dc4f82984e342f58904f0a8ed7288d25549f2d28680ca7b6205efe87
|
File details
Details for the file refcontainer-0.0.3-py3-none-any.whl.
File metadata
- Download URL: refcontainer-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9704f436e15a2e1aa9be8d67d821efabcccf212a4f39a20c629c79e2b51c1cd
|
|
| MD5 |
22152de6b0e1d963ae7f9a9b4e2e7207
|
|
| BLAKE2b-256 |
6d5d58c5cb773d1ba3d11e649fa510bcbcd8e698bcdbbb1387847d3b089e2620
|