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:

from supers import supers

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.7.tar.gz (3.0 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.7-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: supers-0.1.7.tar.gz
  • Upload date:
  • Size: 3.0 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.7.tar.gz
Algorithm Hash digest
SHA256 bdb520e9b75a108d8377b29f0643888fc8a4c406755d1c059dfc09eca5d6c69f
MD5 b153b25e5000c9981d1e44fd833a6344
BLAKE2b-256 e54f141d92b5a5cac0139251414edfaf2bc558e8311c054f7cafab3a5dacbf10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: supers-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 4.1 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1e97550a8d6657dc6e5718efc8b7f375d7df45cf8ff76baaf96775ce12f6f2d0
MD5 2acac80d987608cd7fd2a5173d91c24e
BLAKE2b-256 2e913313e3f18f6ca7db8ec8dfbc45f18248a809d86f2e654d36d1d599e1168b

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