Metadata-Version: 2.1
Name: refcontainer
Version: 0.0.3
Summary: A fully typed Ref(...) object to reference a value, with runtime typechecking.
Project-URL: Homepage, https://github.com/balintmaci/python-ref
Project-URL: Bug Tracker, https://github.com/balintmaci/python-ref/issues
Author: Balint Barna Kovari
License: MIT License
        
        Copyright (c) 2022 balintmaci
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# 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

```python
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 `-e` with install to link sources to installation

Build:

```
python -m build .
```

Push to PyPI:

```
python3 -m twine upload --repository pypi dist/*
```
