Python Strict Interfaces
Installation
pip install strict-interfaces
Design Goals
- Be as strict as possible
- Fail on import time
- Do not mess with
objectand/ortypeinheritance - Possibility to integrate in CPython Core
- Ability to use "out of the box" regardless support in an interpreter
Features
- Special keyword
implementson the class definition - Multiple interface implementation
- Implicit interface implementation
- Interface inheritance with overloading being restricted
- Special
isimplementationfunction similar toissubclass - Partial
issubclasssupport (see below) - It's restricted to create an interface instance
- It's restricted to inherit from
objectandinterfaceat the same time
Usage
Explicit implementation
class TestInterface(interfaces.interface):
def method(self, arg: typeT1) -> typeT2:
pass
class TestClass(interfaces.object, implements=[TestInterface]):
def method(self, arg: typeT1) -> typeT2:
pass
Raises when is not implemented
class TestInterface(interfaces.interface):
def method(self, arg):
pass
class TestClass(interfaces.object, implements=[TestInterface]):
pass
Implicit implementation and run-time check
class TestInterfaceA(interfaces.interface):
def method_a(arg: typeT1) -> typeT1:
pass
class TestInterfaceB(interfaces.interface):
def method_b(arg: typeT2) -> typeT2:
pass
class TestClass:
def method_a(arg: typeT1) -> typeT1:
pass
def method_b(arg: typeT2) -> typeT2:
pass
assert interfaces.isimplementation(TestClass, (TestInterfaceA, TestInterfaceB))
isimplementation checks whether all interfaces are implemented
class TestInterfaceA(interfaces.interface):
def method_a(arg: typeT1) -> typeT1:
pass
class TestInterfaceB(interfaces.interface):
def method_b(arg: typeT2) -> typeT2:
pass
class TestClass:
def method_a(arg: typeT1) -> typeT1:
pass
# NOTE: In this case `isimplementation` behaves different than `issubclass`
assert not interfaces.isimplementation(TestClass, (TestInterfaceA, TestInterfaceB))
assert issubclass(TestClass, (TestInterfaceA, TestInterfaceB))
Contributing
Pull requests, feature requests, and bug reports are always welcome!
Metadata
Release files for strict-interfaces 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| strict-interfaces-0.1.2.tar.gz | 11.8 kB | Without provenance | Details for strict-interfaces-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| strict_interfaces-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for strict_interfaces-0.1.2-py3-none-any.whl |
Total release size: 24.8 kB
Release files / strict-interfaces-0.1.2.tar.gz
| Download URL | strict-interfaces-0.1.2.tar.gz |
|---|---|
| Size | 11.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0560785c5986b103a11495c110f153d4d5774461f2f0dbd3c8cce9e7c7e5be14
|
|
BLAKE2b-256 checksum How to use checksums |
d52be908efc32da7b171d271c21a5b60224aa65bfbc61c3ee89f005b545d00db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.20.1
|
Release files / strict_interfaces-0.1.2-py3-none-any.whl
| Download URL | strict_interfaces-0.1.2-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
407e59ee63b3a07f5c7ca91711499acca0b6a8675c037a3bdfb031cea54693e2
|
|
BLAKE2b-256 checksum How to use checksums |
1b070220b533a43c6486ba5cf14d73eeec2152172a71c28cd55327a6d2458e9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.20.1
|
Security for strict-interfaces 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.