Skip to content

rykener/better-abc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Python ABC plus abstract attributes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages