Skip to content

Commit

Permalink
#49: Refactor __repr__ in SongData for cleaner attribute handling.
Browse files Browse the repository at this point in the history
Simplified the `__repr__` method by introducing a helper function to format attributes and streamline their inclusion. This improves code readability and reduces redundancy without altering functionality.
  • Loading branch information
kozaka-tv committed Dec 30, 2024
1 parent 97c431c commit 5cebad6
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions modules/servant/song_loader/song_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,19 @@ def is_official(self):
return self.rspl_official in KEY_VALUES_OF_AN_OFFICIAL_CDLC

def __repr__(self):
rep = '<SongData: '

if self.song_filename:
rep += f"song_filename={self.song_filename}, "

if self.artist_title:
rep += f"artist_title={self.artist_title}, "

if self.rspl_request_id:
rep += f"rspl_request_id={self.rspl_request_id}, "
if self.cdlc_id:
rep += f"cdlc_id={self.cdlc_id}, "
if self.rspl_song_id:
rep += f"rspl_song_id={self.rspl_song_id}, "
if self.rspl_official:
rep += f"rspl_official={self.rspl_official}, "
if self.rspl_position:
rep += f"rspl_position={self.rspl_position}, "

if self.tags:
rep += f"tags={self.tags}"

rep += ">"

return rep
def format_attribute(name, value):
return f"{name}={value}" if value else None

attributes = [
format_attribute("song_filename", self.song_filename),
format_attribute("artist_title", self.artist_title),
format_attribute("rspl_request_id", self.rspl_request_id),
format_attribute("cdlc_id", self.cdlc_id),
format_attribute("rspl_song_id", self.rspl_song_id),
format_attribute("rspl_official", self.rspl_official),
format_attribute("rspl_position", self.rspl_position),
format_attribute("tags", self.tags)
]

attributes_str = ", ".join(attr for attr in attributes if attr)
return f"<SongData: {attributes_str}>"

0 comments on commit 5cebad6

Please sign in to comment.