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.
The classic interface example, Animal:
from strictabc import StrictABC, strictabstract
class Animal(StrictABC):
@strictabstract
def speak(self)->str:
passLater implementing concrete classes:
class A10Warthog(Animal):
def speak(self)->str:
return "Brrrrrrrrrt!"
class Warthog(Animal):
passThe 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>)]
>>>Licensed under the MIT License.