Skip to content

Instantly share code, notes, and snippets.

@RobinRamael
Created July 31, 2019 13:49
Show Gist options
  • Select an option

  • Save RobinRamael/b1f6d05d7c414f548bd6c1107c0f71cc to your computer and use it in GitHub Desktop.

Select an option

Save RobinRamael/b1f6d05d7c414f548bd6c1107c0f71cc to your computer and use it in GitHub Desktop.
class VersionedAttribute:
def __init__(self, status_sequence):
self.value_status_mapping = {state: None for state in status_sequence}
def __get__(self, instance, owner):
return self.value_for(instance.status)
def __set__(self, instance, value):
self.value_status_mapping[instance.status] = value
def value_for(self, status):
return self.value_status_mapping[status]
PLANNING = 1
FILLING_IN = 2
CORRECTING = 3
class Assignment(object):
status = PLANNING
start_time = VersionedAttribute([PLANNING, FILLING_IN, CORRECTING])
a = Assignment()
a.start_time = "around nine-ish"
print(a.start_time)
a.status = FILLING_IN
a.start_time = "the fuck he only showed up after lunch and didn't do shit"
print(a.start_time)
a.status = PLANNING
print(a.start_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment