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.8.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.8-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: interfacetools-1.0.8.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.8.tar.gz
Algorithm Hash digest
SHA256 3503ac6db2d376261591c819d7bb92775cb239d0ee87b68fa2a1569227425c34
MD5 79a9f2ffa18f5ed03f1e15e4967c79aa
BLAKE2b-256 dac8156d3f6a0fa068371f84c033327ff745b7284eb615aec29d9de6488f5197

See more details on using hashes here.

File details

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

File metadata

  • Download URL: InterFaceTools-1.0.8-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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 b7c722aede81b66b0930f166907b7235f3afe15f5fd0708c95cb62f9a6990997
MD5 55affcaa78ccdce511a5a4a3e02ade89
BLAKE2b-256 bfadb4879eb3d88235a7f8b2fdffaafa48347e05774e885d114e32cba3a28016

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