Skip to content

taviken/strictabc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Repository of python package strictabc

The strict abc package implements a subclass of the builtin ABCMeta and ABC classes. Its behavior checks that all marked methods are implemented and have the correct function signature. This is done at creation of the class, before any instatiation attempts. It allows for developers of abstract classes and interfaces to enforce implementation earlier.

Example

The classic interface example, Animal:

from strictabc import StrictABC, strictabstract


class Animal(StrictABC):

    @strictabstract
    def speak(self)->str:
        pass

Later implementing concrete classes:

class A10Warthog(Animal):

    def speak(self)->str:
        return "Brrrrrrrrrt!"

class Warthog(Animal):
    pass

The concrete class 'A10Warthog' will pass the checks that 'StrictABC' performs. The other 'Warthog' class will not pass, and a 'StrictAbstractError' will be thrown'.

>>> from concrete import *
. strictabc.strict.StrictAbstractError: Errors in <Warthog>
. Missing methods: ['speak']
. Missmatched signatures detected: None
>>>

Or, if the 'speak' signature doesn't match, a similar exception will be thrown.

class Warthog(Animal):
    def speak(cls)->str:
        return 'oh the shame ... And I got downhearted, everytime....!'

Giving the following exception:

. strictabc.strict.StrictAbstractError: Errors in <Warthog>
. Missing methods: None
. Missmatched signatures detected: [miss_matched_sigs(method_name='speak', good_sig=<Signature (self) -> str>, bad_sig=<Signature (cls) -> str>)]
>>>

License

Licensed under the MIT License.

About

Repository of python package strictabc

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages