Skip to content

Commit

Permalink
UriHolder: use returns of changers to indicate an action
Browse files Browse the repository at this point in the history
- it now does not need to check for changes
- rather, its return value is usuable for overriding methods as they now
  know if the super already did something if they choose to call it
  • Loading branch information
Zocker1999NET committed Jul 2, 2023
1 parent 7d47b95 commit fa91114
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions server/entertainment_decider/models/extras/uris.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,22 @@ def _primary_uri(self) -> str:
"""Returns the primary uri of this object in a naive way."""

@abstractmethod
def _set_primary_uri(self, uri: str) -> None:
"""Sets the primary uri of this object in a naive way."""
def _set_primary_uri(self, uri: str) -> bool:
"""Sets the primary uri of this object in a naive way.
Returns True if an action was applied, False otherwise.
If the uri was already primary,
both True or False might be returned.
When overriding this method,
if you call the super() and its call returns True,
you should avoid making changes yourself.
A final non-abstract version of this method must throw an error
if it fails to set the primary uri instead of just returning False.
The return value is mainly for overwriting methods to divert the change.
"""
return False

@abstractproperty
def _uri_set(self) -> Set[str]:
Expand All @@ -34,15 +48,37 @@ def _clear_uri_set(self) -> None:
def _add_uri_to_set(self, uri: str) -> bool:
"""Adds a uri to the uri set of this object in a naive way.
Returns True if the uri was not in the uri set before.
Returns True if an action was applied, False otherwise.
If the uri was already part of the uri set,
both True or False might be returned.
When overriding this method,
if you call the super() and its call returns True,
you should avoid making changes yourself.
A final non-abstract version of this method must throw an error
if it fails at adding the uri instead of just returning False.
The return value is mainly for overwriting methods to divert the change.
"""
return False

@abstractmethod
def _remove_uri_from_set(self, uri: str) -> bool:
"""Removes a uri to the uri set of this object in a naive way.
Returns True if the uri was in the uri set before.
Returns True if a change was applied, False otherwise.
If the uri was already absent from the uri set,
both True or False might be returned.
When overriding this method,
if you call the super() and its call returns True,
you should avoid making changes yourself.
A final non-abstract version of this method must throw an error
if it fails at removing the uri instead of just returning False.
The return value is mainly for overwriting methods to divert the change.
"""
return False

### implemented

Expand Down

0 comments on commit fa91114

Please sign in to comment.