Skip to main content
https://badge.fury.io/py/ipromise.svg

A Python base class that provides various decorators for specifying promises relating to inheritance. It provides three inheritance patterns:

  • implementing,

  • augmenting, and

  • overriding.

Implementing

Implementing is the pattern whereby an inheriting class’s method implements an abstract method from a base class method. It is declared using the decorators:

  • abc.abstractmethod from the standard library, and

  • implements, which indicates that a method implements an abstract method in a base class

For example:

class HasAbstractMethod(AbstractBaseClass):

    @abstractmethod
    def f(self):
        raise NotImplementedError


class ImplementsAbstractMethod(HasAbstractMethod):

    @implements(HasAbstractMethod)
    def f(self):
        return 0

Augmenting

Augmenting is the pattern whereby an inheriting class’s method calls a base class method. This pattern is typical in multiple inheritance whereby mixins provide additional behavior. It is declared using two decorators:

  • augments indicates that this method must call super within its definition and thus augments the behavior of the base class method, and

  • must_agugment indicates that child classes that define this method must decorate their method overriddes with augments.

For example:

class HasMustAugmentMethod(AbstractBaseClass):

    @must_augment
    def f(self):
        # must_augment prevents this behavior from being lost.
        self.times_f_called += 1
        return 0


class AugmentsMethod(HasMustAugmentMethod):

    @augments(HasMustAugmentMethod)
    def f(self, extra=0, **kwargs):
        return super().f(**kwargs) + extra


class AlsoAugmentsMethod(HasMustAugmentMethod):

    @augments(HasMustAugmentMethod)
    def f(self, **kwargs):
        print("f has been called")
        return super().f(**kwargs)

Overriding

Overriding is the pattern whereby an inheriting class’s method calls a base class method. This pattern indicates that the base class method is hidden (at least in some cases). It is declared using the decorator overrides, which indicates that this is an overriding method. Such a method could call super, but does not have to:

class HasRegularMethod(AbstractBaseClass):

    def f(self):
        return 1


class OverridesRegularMethod(HasRegularMethod):

    @overrides(HasRegularMethod)
    def f(self):
        return 2

Metadata

Release files for ipromise 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ipromise 1.1
File Size Uploaded
ipromise-1.1.linux-x86_64.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ipromise 1.1
File Interpreter ABI Platform
ipromise-1.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / ipromise-1.1.linux-x86_64.tar.gz

Download URL ipromise-1.1.linux-x86_64.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8f066e978dbc6f35ab6845f2829cb660b7b66b30ccbee1fa5a81c37a06c08206
BLAKE2b-256 checksum
How to use checksums
476239e775cf883b6aff09f566fe5b5e78764f97b35d48a0ec1adf62fbe6e1f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.0

Release files / ipromise-1.1-py3-none-any.whl

Download URL ipromise-1.1-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6da9148196c5b0bf82107da9f0c339a9d81c4074aaf8010dabd0a6388adc8afe
BLAKE2b-256 checksum
How to use checksums
b6db59bc861d9090bba8449c3332e8330440a6537c6d501ab01805b05b2e4626
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.0

Release history Release notifications | RSS feed

1.9

2 release files

1.8

2 release files

1.7

2 release files

1.6

1 release file

1.5

2 release files

1.4

1 release file

1.3

1 release file

1.2

2 release files

This release

1.1 This release

2 release files

1.0

2 release files

0.75

1 release file

0.65

1 release file

0.9

3 release files

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page