Post init hook is called after frozen, not allowing adding variables that only make sense in an instance context.
import attr
import logbook
import sys
from logbook import StreamHandler
StreamHandler(sys.stdout).push_application()
@attr.s
class Example(object):
x = attr.ib()
y = attr.ib()
def __attrs_post_init__(self):
# bypass frozen on lower classes
# self._log = logbook.Logger(self.__class__.__name__) causes a Frozen exception in child
object.__setattr__(self, "_log", logbook.Logger(self.__class__.__name__))
@attr.s(frozen=True)
class Child(Example):
def do(self):
self._log.info("hi")
Child(1, 2).do()
Post init hook is called after frozen, not allowing adding variables that only make sense in an instance context.