Skip to content

A light-weight python package for controlling class attributes.

License

Notifications You must be signed in to change notification settings

lejar/traitlite

Repository files navigation

Build Status

traitlite

Traitlite is a light-weight (MIT-licensed) package which provides certain descriptors to help control the attributes in a class, such as making them read-only* or providing type-checking whenever the value is set.

Here's a quick example that shows what it does, but the documentation has examples for every trait, so check it out!

from traitlite import ReadOnly, TypeChecked
class Foo:
    bar = TypeChecked(int) + ReadOnly()

    def __init__(self, bar):
        self.bar = bar

Foo(3.0) # Raises exception
foo = Foo(3) # Okay
foo.b = 2 # Raises exception because of read-only

* well, as read-only as you can get in python

Installation

The easiest way to install traitlite is through pip:

pip install traitlite

Running the tests

Traitlite uses the builtin python unit testing framework, along with hypothesis. Additionally, cosmic-ray is used for mutation testing.

To install the dependencies required to run the tests, run:

pip install -r unittest_requirements.txt

This will install both hypothesis and cosmic-ray.

To run the tests, simply execute the following from the package directory:

python setup.py test

To run mutation testing, execute:

python setup.py crtest

If you want to get the coverage of the tests, execute:

python setup.py coverage

Documentation

The docs can be found here. Alternatively, if you want to build them yourself simply run

make <target>

in the docs folder of the project. To see a list of all the different targets, simply run make without any arguments.

About

A light-weight python package for controlling class attributes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages