[gnome-music/wip/mschraal/type-checking: 26/28] coresong: Add static typing



commit 9a60a38f7100869636f4a61800dda0b8bf4aafed
Author: Marinus Schraal <mschraal gnome org>
Date:   Sat May 30 14:12:57 2020 +0200

    coresong: Add static typing

 gnomemusic/coresong.py | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
---
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index c7756e63..73240b74 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -23,12 +23,15 @@
 # delete this exception statement from your version.
 
 from enum import IntEnum
+import typing
 
 import gi
 gi.require_version('Grl', '0.3')
 from gi.repository import Grl, GLib, GObject
 
 from gnomemusic.songart import SongArt
+if typing.TYPE_CHECKING:
+    from gnomemusic.application import Application
 import gnomemusic.utils as utils
 
 
@@ -56,7 +59,7 @@ class CoreSong(GObject.GObject):
         FAILED = 2
         SUCCEEDED = 3
 
-    def __init__(self, application, media):
+    def __init__(self, application: "Application", media: Grl.Media) -> None:
         """Initiate the CoreSong object
 
         :param Application application: The application object
@@ -76,7 +79,7 @@ class CoreSong(GObject.GObject):
         self.props.validation = CoreSong.Validation.PENDING
         self.update(media)
 
-    def __eq__(self, other):
+    def __eq__(self, other: object) -> bool:
         return (isinstance(other, CoreSong)
                 and other.props.media.get_id() == self.props.media.get_id())
 
@@ -86,11 +89,11 @@ class CoreSong(GObject.GObject):
         return self._is_tracker
 
     @GObject.Property(type=bool, default=False)
-    def favorite(self):
+    def favorite(self) -> bool:
         return self._favorite
 
     @favorite.setter  # type: ignore
-    def favorite(self, favorite):
+    def favorite(self, favorite: bool) -> None:
         if not self._is_tracker:
             return
 
@@ -105,11 +108,11 @@ class CoreSong(GObject.GObject):
         self._coregrilo.writeback(self.props.media, Grl.METADATA_KEY_FAVOURITE)
 
     @GObject.Property(type=bool, default=False)
-    def selected(self):
+    def selected(self) -> bool:
         return self._selected
 
     @selected.setter  # type: ignore
-    def selected(self, value):
+    def selected(self, value: bool) -> None:
         if not self._is_tracker:
             return
 
@@ -120,7 +123,7 @@ class CoreSong(GObject.GObject):
         self._coreselection.update_selection(self, self._selected)
 
     @GObject.Property(type=str, default=None)
-    def thumbnail(self):
+    def thumbnail(self) -> str:
         """Song art thumbnail retrieval
 
         :return: The song art uri or "generic" or "loading"
@@ -132,15 +135,15 @@ class CoreSong(GObject.GObject):
 
         return self._thumbnail
 
-    @thumbnail.setter
-    def thumbnail(self, value):
+    @thumbnail.setter  # type: ignore
+    def thumbnail(self, value) -> None:
         """Song art thumbnail setter
 
         :param string value: uri, "generic" or "loading"
         """
         self._thumbnail = value
 
-    def update(self, media):
+    def update(self, media: Grl.Media) -> None:
         self.props.media = media
         self.props.album = utils.get_album_title(media)
         self.props.album_disc_number = media.get_album_disc_number()
@@ -152,7 +155,7 @@ class CoreSong(GObject.GObject):
         self.props.track_number = media.get_track_number()
         self.props.url = media.get_url()
 
-    def bump_play_count(self):
+    def bump_play_count(self) -> None:
         if not self._is_tracker:
             return
 
@@ -160,7 +163,7 @@ class CoreSong(GObject.GObject):
         self._coregrilo.writeback(
             self.props.media, Grl.METADATA_KEY_PLAY_COUNT)
 
-    def set_last_played(self):
+    def set_last_played(self) -> None:
         if not self._is_tracker:
             return
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]