Skip to main content

automatic typed collections in python using decorators

Project description

This is a python library for typed containers – it makes it safer & easier to work with lists & dicts of items of the same type by providing:

  • type checks

  • container methods

  • automatic dictionary keys

Example:

import containers

@containers.container_class
class Item:
    def __init__(self, x):
        self.x = x

    @containers.container_method()
    def sum(container):
        return sum(item.x for item in container)

    @containers.container_key
    def key(self):
        return self.x

list_ = Item.container(list)
list_.append(Item(1))
list_.append(Item(2))

# items of incompatible type are rejected
with pytest.raises(TypeError):
    list_.append(3)

# container_method methods are available on the list
assert list_.sum() == 3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

containers-0.0.3.tar.gz (2.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page