Skip to main content

A module containing the implementation of Strict ABC classes and decorators

Project description

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.

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

strictabc-1.0.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

strictabc-1.0.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file strictabc-1.0.2.tar.gz.

File metadata

  • Download URL: strictabc-1.0.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for strictabc-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a4a4e2daf57b57a8516651c02f9aae6e11a1e2c6ef3153607717652ee64cd4cf
MD5 e33774932a355ab474a6bbf187aa6adf
BLAKE2b-256 7dd2dafebfd155a1f6781bf3cbe2254c505f5d38f2fbd0f783dce7c88dc2316b

See more details on using hashes here.

File details

Details for the file strictabc-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: strictabc-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for strictabc-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e8939a0e294230bcf87948f038ca5c0ed936e3f866055c7889650ea667871ff0
MD5 c5ca64c0b70c025346ec1cadba41eb54
BLAKE2b-256 e2f2ea9a8e1877dee4ed7ef4dd06d07bd7e86f2fc0f24d55601b8859df5d7da3

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