diff --git a/src/music_kraken/objects/parents.py b/src/music_kraken/objects/parents.py index 58b235d..5a0c245 100644 --- a/src/music_kraken/objects/parents.py +++ b/src/music_kraken/objects/parents.py @@ -53,7 +53,7 @@ class MainObject(DatabaseObject): """ def __init__(self, _id: str = None, dynamic: bool = False, **kwargs): - super().__init__(_id=_id, dynamic=dynamic, **kwargs) + DatabaseObject.__init__(self, _id=_id, dynamic=dynamic, **kwargs) self.additional_arguments: dict = kwargs diff --git a/src/music_kraken/objects/song.py b/src/music_kraken/objects/song.py index d1a05aa..44db669 100644 --- a/src/music_kraken/objects/song.py +++ b/src/music_kraken/objects/song.py @@ -167,6 +167,9 @@ class Song(MainObject, SourceAttribute, MetadataAttribute): album_list: List[Type['Album']] = property(fget=lambda self: self.album_collection.copy()) lyrics_list: List[Type[Lyrics]] = property(fget=lambda self: self.lyrics_collection.copy()) + COLLECTION_ATTRIBUTES = ("lyrics_collection", "album_collection", "main_artist_collection", "feature_artist_collection") + SIMPLE_ATTRIBUTES = ("title", "isrc", "length", "tracksort", "genre") + """ All objects dependent on Album @@ -317,6 +320,10 @@ class Album(MainObject, SourceAttribute, MetadataAttribute): tracklist: List[Song] = property(fget=lambda self: self.song_collection.copy()) copyright = property(fget=get_copyright) + + COLLECTION_ATTRIBUTES = ("label_collection", "artist_collection", "song_collection") + SIMPLE_ATTRIBUTES = ("title", "album_status", "album_type", "language", "date", "barcode", "albumsort") + """ All objects dependent on Artist @@ -460,7 +467,7 @@ class Artist(MainObject, SourceAttribute, MetadataAttribute): return flat_copy_discography - album_list: List[Album] = property(fget=lambda self: self.album_collection.copy()) + album_list: List[Album] = property(fget=lambda self: self.main_album_collection.copy()) complete_album_list: List[Album] = property(fget=get_discography) discography: List[Album] = property(fget=get_discography) @@ -468,6 +475,9 @@ class Artist(MainObject, SourceAttribute, MetadataAttribute): feature_album: Album = property(fget=get_features) song_list: List[Song] = property(fget=get_all_songs) label_list: List[Type['Label']] = property(fget=lambda self: self.label_collection.copy()) + + COLLECTION_ATTRIBUTES = ("feature_song_collection", "main_album_collection", "label_collection") + SIMPLE_ATTRIBUTES = ("name", "name", "country", "formed_in", "notes", "lyrical_themes", "general_genre") """ @@ -511,3 +521,6 @@ class Label(MainObject, SourceAttribute, MetadataAttribute): @property def current_artist_list(self) -> List[Artist]: self.current_artist_collection.copy() + + COLLECTION_ATTRIBUTES = ("album_collection", "current_artist_collection") + SIMPLE_ATTRIBUTES = ("name",) diff --git a/src/music_kraken/objects/source.py b/src/music_kraken/objects/source.py index fae6ca1..1262ebf 100644 --- a/src/music_kraken/objects/source.py +++ b/src/music_kraken/objects/source.py @@ -126,7 +126,7 @@ class Source(DatabaseObject, MetadataAttribute): homepage = property(fget=lambda self: SourcePages.get_homepage(self.page_enum)) -class SourceAttribute: +class SourceAttribute(DatabaseObject): """ This is a class that is meant to be inherited from. it adds the source_list attribute to a class @@ -187,6 +187,12 @@ class SourceAttribute: and the value is a List with all sources of according page """ return self._source_dict + + def merge(self, other, override: bool = False): + super().merge(other, override) + + for source in other.source_list: + self.add_source(source=source) source_list: List[Source] = property(fget=get_source_list, fset=set_source_list) source_dict: Dict[object, List[Source]] = property(fget=get_source_dict) diff --git a/src/music_kraken/pages/encyclopaedia_metallum.py b/src/music_kraken/pages/encyclopaedia_metallum.py index aab3a48..be8bd78 100644 --- a/src/music_kraken/pages/encyclopaedia_metallum.py +++ b/src/music_kraken/pages/encyclopaedia_metallum.py @@ -237,17 +237,6 @@ class EncyclopaediaMetallum(Page): except ValueError(): pass - - album_obj: Album = artist.main_album_collection.get_object_with_source(album_url) or artist.main_album_collection.get_object_with_attribute("title", album_name) - - if album_obj is not None: - album_obj.add_source(Source(SourcePages.ENCYCLOPAEDIA_METALLUM, album_url)) - album_obj.title = album_name - album_obj.album_type = album_type - if date_obj is not None: - album_obj.date = date_obj - continue - artist.main_album_collection.append(Album( id_=album_id, title=album_name, diff --git a/src/python.py b/src/python.py new file mode 100644 index 0000000..af1c3e7 --- /dev/null +++ b/src/python.py @@ -0,0 +1,61 @@ +class SuperFoo: + ATTRIBUTES: tuple = tuple() + +class Foo(SuperFoo): + def __init__(self, bar1, bar2, bar3) -> None: + self.bar1 = bar1 + self.bar2 = bar2 + self.bar3 = bar3 + + ATTRIBUTES: tuple = ("bar1", "bar2", "bar3") + + +def process(child_instance: SuperFoo): + for attribute in child_instance.ATTRIBUTES: + print(getattr(child_instance, attribute)) + +process(Foo(123, 456, 789)) + +""" +Hi! + +I got following code *(It is a very simplified and broken down example)*: + +```python +class SuperFoo: + ATTRIBUTES: tuple = tuple() + +class Foo(SuperFoo): + def __init__(self, bar1, bar2, bar3) -> None: + self.bar1 = bar1 + self.bar2 = bar2 + self.bar3 = bar3 + + ATTRIBUTES: tuple = (Foo.bar1, Foo.bar2, Foo.bar3) + + +def process(child_instance: SuperFoo): + for attribute in child_instance.ATTRIBUTES: + print(getattr(child_instance, attribute)) + +process(Foo(123, 456, 789)) +``` + +the output I expect would be: + +``` +> 123 +> 456 +> 789 +``` + +Obviously this doesn't work, instead the IDE warns me that `Foo` is not defined, and the error which is raised says so as well. + +``` +ATTRIBUTES: tuple = (Foo.bar1, Foo.bar2, Foo.bar3) +NameError: name 'Foo' is not defined +``` + +While I completely get why this happens, I have no clue how to solve it. +Any help would be appreciated. +""" \ No newline at end of file