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

Uploaded Python 3

File details

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

File metadata

  • Download URL: strictabc-1.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 04460a01a3bf19c529fe975419690f0a19299ecc04268eec0875ca00a2494699
MD5 8028959af09e198fcaf2f276e5d333ab
BLAKE2b-256 a67a5843547d84eec6d4ae480d71b6cb54b16fe74549274878464894418f1a65

See more details on using hashes here.

File details

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

File metadata

  • Download URL: strictabc-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ac8183dcb12d90f8946ab69dd2b435f5c76d14a50174c30c11f0ea1f76abffd4
MD5 239da742698bed40fba4e2f1431c1313
BLAKE2b-256 a56099c4fc51de53983803604f12d3341b7c020dce75af8563dda553aa096d06

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