Skip to main content

allows for @interface class partail behavoiur decorator

Project description

Interface Decorator

allows the use of the @Interface class decorator, which allows for partial interface behavior currently only preventing direct instantiation. future features hope to include method detection and force children implementations, however, this can be accomplished with the ABC package.

this package is designed to be light weight and extremely simple to use. one @ to rule them all. in this case, enforcing typical interface behaviors with good readability.

install windows

pip install InterfaceTools

Mac

pip3 install InterfaceTools

Instructions:

above any classes you wish to become an interface and restrict instantaition to only children:

from Leviathan.interface import Interface

@interface
class MyClass():

    def __init__(self, *args,**kwargs):
       pass 

    def Method():pass

that is all there is to it. this decorator then restricts this class never to instantiate on its own; meaning the following:

foo = MyClass()

which gives the following error:

InterfaceInstancingError: The class MyClass is an interface. Interfaces cannot be instantiated.

each interface requires the follwoing init function to allow for parameters, it can stay empty.

   def __init__(self, *args,**kwargs):
       pass 

Additionally, unlike interfaces in C# or Java, you are not required to implement their methods. however, if you desire that functionality you can use this with the ABC package to enforce children-overriding methods

example:

from abc import ABCMeta, abstractmethod

@Interface 
class myClass(metaclass=ABCMeta):
    
    def __init__(self, *args,**kwargs):
       pass 
    
    @abstractmethod
    def method():pass

the example above will give you a full C# or Java-like interface.

other things you can do with this module are interface inheritance:

example:

@Interface 
class myClass():
    pass
@Interface
class class2(myClass):
    pass

which you can also inherit from regular classes as well.

class myClass():
    pass
@Interface
class class2(myClass):
    pass

the interface wrapper is fully compatible with all the default Python functions, and the ABC package for further control over your interface.

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

interfacetools-1.0.9.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

InterFaceTools-1.0.9-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file interfacetools-1.0.9.tar.gz.

File metadata

  • Download URL: interfacetools-1.0.9.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for interfacetools-1.0.9.tar.gz
Algorithm Hash digest
SHA256 1a5e1cdf64e9cacddc189b3e9ba4f83f4c6c6c11cc37f4a99aecf9ea303ff466
MD5 40d2cd50f16475643f9e20198dcfe2db
BLAKE2b-256 58a164760ff22f17b8ffa43db4d0ff70f50190d488670e07b033397317848d8e

See more details on using hashes here.

File details

Details for the file InterFaceTools-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: InterFaceTools-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for InterFaceTools-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 b5cd7a73265f3801e7814638235ddc81317d2d6c05bec961605f62a8f8128b55
MD5 bbe4dd5cd995f1dbab98cdabb5a943fb
BLAKE2b-256 45d6459cd9b6781e47cf17337497f3ae539ef29f6d4f108532999cf9a8c0fca0

See more details on using hashes here.

Supported by

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