Supers: Call a function in all superclasses as easy as supers(self).foo(42)
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.6.tar.gz
(2.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file supers-0.1.6.tar.gz.
File metadata
- Download URL: supers-0.1.6.tar.gz
- Upload date:
- Size: 2.8 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78a3a7657508f0ad3640a0bfa2a3d8e913c798987b3ba69be8e26478d004137f
|
|
| MD5 |
0d4b4938574e1aa172c5c544e66592ba
|
|
| BLAKE2b-256 |
8fd0c9158e37374b05e8a3714dd1aa5e9c73012e4dba6b497d6f9c5e17f4f67c
|
File details
Details for the file supers-0.1.6-py3-none-any.whl.
File metadata
- Download URL: supers-0.1.6-py3-none-any.whl
- Upload date:
- Size: 3.8 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
564ad34c28bf18ee0785efd38b41d3be2c8bcb22280aad3b758f6744331c30b8
|
|
| MD5 |
71e0d526501d613418bbf94ce1c3a41e
|
|
| BLAKE2b-256 |
7f66ac4aefc30034dd87da96a06b47b9ad3eafb97e9694520ccba4157110a1e3
|