Last active
March 6, 2017 22:08
-
-
Save wsanchez/91b80229f4ff4aff978e7a9ad8e39720 to your computer and use it in GitHub Desktop.
Private mutable state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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