This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Utility for easy object composition via delegation. Roughly ported from Ruby’s forwardable standard library.

Requirements

Python 2.7 or 3.3 w/ standard library. Might work on other version of Python, too.

Installation

$ pip install forwardable

Usage

Most Common Use Case

The @forwardable.forwardable() decorator enables you to use def_delegator() and def_delegators() in a class definition block.

Use def_delegators() to define multiple attr forwarding:

from forwardable import forwardable

@forwardable() # Note the () here, which is required.
class Foo(object):
    def_delegators('bar', 'add, __len__')

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

foo = Foo()
foo.add(1) # Delegates to foo.bar.add()
assert len(foo) == 1 # Magic methods works, too

Easy, heh?

Define a Single Forwarding

In case you only need to delegate one method to a delegatee, just use def_delegator:

from forwardable import forwardable

@forwardable()
class Foo(object):
    def_delegator('bar', '__len__')

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

assert len(Foo()) == 0

And it should work just fine. Actually, def_delegators() calls def_delegator() under the hood.

Plucking

from forwardable import forwardable

@forwardable()
class MyDict(object):
    def_delegator('dct.get', '__call__')
    def __init__(self):
        self.dct = {'foo', 42}

d = MyDict()
# Equivlant to d.dct.get('foo')
assert d('foo') == 42

Less Magical Usage

The @forwardable() decorator injects def_delegator{,s} into the module scope temorarily, which is why you don’t have to import them explicitly. This is admittedly magical but discourages the usage of import *. And it’s always nice to type less characters whenever unnecessary.

If you hesitate to utilize this injection magic, just explicitly say from forwardable import def_delegator, def_delegators, use them in a class definition and you’ll be fine.

License

MIT license.

Release History

Release History

0.4.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
forwardable-0.4.1.tar.gz (5.1 kB) Copy SHA256 Checksum SHA256 Source May 17, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting