Skip to main content

Provides the Interface class and other interface utilities.

Project description

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.

from good_interface import Interface

@Interface
class MyInterface:
    def method1(self, arg1, arg2):
        pass

    def 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.

from good_interface import Interface

@Interface
class MyInterface:
    def method1(self, arg1, arg2):
        pass

    def method2(self, arg2):
        pass

@MyInterface
class MyClass:
    def method1(self, arg1, arg2):
        pass

    def 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

from good_interface import Interface

@Interface
class MyInterface1:
    def method1(self):
        pass

@MyInterface1
@Interface
class MyInterface2:
    def method2(self, arg1, arg2):
        pass

    def method3(self, arg2):
        pass

# Creates:
#
# @Interface
# class MyInterface2:
#     def method1(self):
#         pass
#
#     def method2(self, arg1, arg2):
#         pass
#
#     def method3(self, arg2):
#         pass

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

good-interface-1.0.1.tar.gz (2.5 kB view details)

Uploaded Source

File details

Details for the file good-interface-1.0.1.tar.gz.

File metadata

File hashes

Hashes for good-interface-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6720a6c1cc75c6a5566204c9c2b2ef857985009aebb2cb45a832cf8186c16474
MD5 8ec7e097543f1ea00b52496c32fb9efb
BLAKE2b-256 202bfb30b110cc7596870376ebe16a2efea4e226394d5422c03271638435e998

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page