Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andydevs/good-interface
Interfaces in python
https://github.com/andydevs/good-interface
interfaces python python3
Last synced: about 20 hours ago
JSON representation
Interfaces in python
- Host: GitHub
- URL: https://github.com/andydevs/good-interface
- Owner: andydevs
- License: mit
- Created: 2018-06-27T01:39:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-22T00:33:37.000Z (about 5 years ago)
- Last Synced: 2024-11-08T21:33:58.321Z (about 2 months ago)
- Topics: interfaces, python, python3
- Language: Python
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# good_interface
Provides the Interface class and other utilities which can define method "interfaces" which automatically check method implementation in classes and objects.
## Interfaces
An Interface is a collection of methods that are to be implemented in classes that implement this Interface. The Interface class can define Interfaces from a class skeleton.
```python
from good_interface import Interface@Interface
class MyInterface:
def method1(self, arg1, arg2):
passdef method2(self, arg2):
pass
```Since the interface is callable, you can call the new Interface object as a decorator on a class, which provides a check on the given class, ensuring that it implements the defined methods in the given interface.
```python
from good_interface import Interface@Interface
class MyInterface:
def method1(self, arg1, arg2):
passdef method2(self, arg2):
pass@MyInterface
class MyClass:
def method1(self, arg1, arg2):
passdef method2(self, arg2):
pass
```Calling the interface on another interface will extends the interface, adding the methods of this current interface to the new interface
```python
from good_interface import Interface@Interface
class MyInterface1:
def method1(self):
pass@MyInterface1
@Interface
class MyInterface2:
def method2(self, arg1, arg2):
passdef method3(self, arg2):
pass# Creates:
#
# @Interface
# class MyInterface2:
# def method1(self):
# pass
#
# def method2(self, arg1, arg2):
# pass
#
# def method3(self, arg2):
# pass
```