Skip to main content

Supers: Call a function in all superclasses as easy as supers(self).foo(42)

Python package codecov Code style: black

Installation

pip install supers

Development installation

pip install -e .[tests,build]

Example

Say you have a class inheriting from multiple parent classes, and you would like a function for each parent. With supers this becomes as easy as:

class Parent1:
    def __init__(self, m:float):
        self.m1 = m * 1

    def mult(self, value):
        return value * self.m1

class Parent2:
    def __init__(self, m:float):
        self.m2 = m * 2

    def mult(self, value):
        return value * self.m2

class Child(Parent1, Parent2):
    def __init__(self, m):
        supers(self).__init__(m)

    def allmult(self, val):
        return supers(self).mult(val)

c = Child(m=10)

# Parent attributes were updated
assert c.m1 == 10 
assert c.m2 == 20

# Parent1.mult is called as expected
assert c.mult(10) == 100

# Each parent is called and results are returned in a list
assert c.allmult(10) == supers(c).mult(10) == [100, 200]

Download files

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

Source Distribution

supers-0.1.0.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

supers-0.1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file supers-0.1.0.tar.gz.

File metadata

  • Download URL: supers-0.1.0.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.10

File hashes

Hashes for supers-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3c5cf32493b3eb3dec8d398184a06bc0879ffdba95ff022b0058d5dd49521249
MD5 e89345e34bd95e57f028e31fce588a22
BLAKE2b-256 4f47c47f6d3bb7a6a05db70d2a6c89e7f1a70cddf097d9571dde12b15de4cf7a

See more details on using hashes here.

File details

Details for the file supers-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: supers-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.10

File hashes

Hashes for supers-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eece1eca7392447f96061514f0fe37b4b81f2d0b353bc8792a2e5d519655ca47
MD5 b5eadfd4de2b8e5924d909f7e161794e
BLAKE2b-256 778523bce0e6a3dd77e4c4474ae2635e776a1b557ac6da9d313581b749a3bf44

See more details on using hashes here.

Supported by

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