Created
July 31, 2019 13:49
-
-
Save RobinRamael/b1f6d05d7c414f548bd6c1107c0f71cc to your computer and use it in GitHub Desktop.
Revisions
-
RobinRamael created this gist
Jul 31, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ 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)