Skip to main content

Python ABC plus abstract attributes

Project description

Better ABC

https://stackoverflow.com/questions/23831510/abstract-attribute-not-property

Usage

from better_abc import ABCMeta, abstract_attribute    # see below

class AbstractFoo(metaclass=ABCMeta):

    @abstract_attribute
    def bar(self):
        pass

class Foo(AbstractFoo):
    def __init__(self):
        self.bar = 3

class BadFoo(AbstractFoo):
    def __init__(self):
        pass
Foo()     # ok
BadFoo()  # will raise: NotImplementedError: Can't instantiate abstract class BadFoo
# with abstract attributes: bar

If you want other features of ABC they need to be imported from the abc module directly.

from abc import abstractmethod
from better_abc import ABCMeta, abstract_attribute

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

better-abc-0.0.3.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

better_abc-0.0.3-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page