Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

delegate attributes of a class to another attribute's properties

Project description

Delegate

A python library for delegation (the metaprogramming feature)

This library adds the @delegate decorator which may be used to delegate attributes from an attribute of the existing class. For example:

from delegate import delegate

class Parent:
    def __init__(self):
        self.a = "a"
        self.b = "b"
        self.d = "d"

# The delegate decorator makes .a and .b available on Child, through its
# "parent" attribute, as though Child had an a and b attribute itself.
@delegate("a", "b", to="parent")
class Child:
    def __init__(self):
        self.parent = Parent()
        self.c = "c"

instance = Child()
assert instance.a == "a"
raised = False
try:
    # But d is not available
    instance.d
except e:
    raised = True

assert raised

Project details


Download files

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

Files for delegate-property, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size delegate_property-0.1.0-py3-none-any.whl (3.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size delegate_property-0.1.0.tar.gz (2.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page