Skip to content

Instantly share code, notes, and snippets.

@dbader
Created February 12, 2017 21:19
Show Gist options
  • Save dbader/04d1d42e71562f946163286f37699dd7 to your computer and use it in GitHub Desktop.
Save dbader/04d1d42e71562f946163286f37699dd7 to your computer and use it in GitHub Desktop.
from abc import ABCMeta, abstractmethod
class Base(metaclass=ABCMeta):
def __init__(self):
self.my_attrib = 42
@abstractmethod
def foo(self):
pass
@property
@abstractmethod
def my_prop(self):
pass
class Concrete(Base):
def __init__(self):
super().__init__()
self.other_attrib = 999
def foo(self):
pass
@property
def my_prop(self):
return self.other_attrib + 1
>>> c = Concrete()
>>> c.my_attrib
42
>>> c.other_attrib
999
>>> c.my_prop
1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment