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]

Release files for supers 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for supers 0.2.0
File Size Uploaded
supers-0.2.0.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for supers 0.2.0
File Interpreter ABI Platform
supers-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.1 kB

Release files / supers-0.2.0.tar.gz

Download URL supers-0.2.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
13c8d40a8ac9af25009a7faca45f40c9bfbe6ff3dae863ccbdb58e998d167f40
BLAKE2b-256 checksum
How to use checksums
93b5a887c6fef337f939c842767a5405e48614378fbf9908b960555284d13fdd
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / supers-0.2.0-py3-none-any.whl

Download URL supers-0.2.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e99cd8856784e10f2c7d392512118d157f2c69b75f234252f0dffd5d33032852
BLAKE2b-256 checksum
How to use checksums
7be2ccab13136645e24d1e25b8181b4b80b12aeb8ab0e058854c059f4174b691
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page