Skip to content

Instantly share code, notes, and snippets.

@wsanchez
Last active March 6, 2017 22:08
Show Gist options
  • Save wsanchez/91b80229f4ff4aff978e7a9ad8e39720 to your computer and use it in GitHub Desktop.
Save wsanchez/91b80229f4ff4aff978e7a9ad8e39720 to your computer and use it in GitHub Desktop.
Private mutable state
@attrs(frozen=True)
class Foo(object):
"""
Something Foo-y
"""
@attrs(frozen=False)
class _State(object):
"""
Internal mutable state for Foo.
"""
thing = attrib(init=False)
# Attribute assigned via init
_path = attrib(validator=optional(instance_of(Path)))
# Private attribute to store internal state
_state = attrib(default=_State(), init=False)
def __attrs_post_init__(self):
self._state.thing = thingFromPath(self._path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment