[gnome-music/wip/mschraal/type-checking] Add minimal intial type checking



commit e70c81f059d5b0ab615042442a22956a32eec490
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed May 27 17:55:10 2020 +0200

    Add minimal intial type checking

 .gitlab-ci.yml         |  6 ++++++
 gnomemusic/coresong.py | 23 ++++++++++++-----------
 2 files changed, 18 insertions(+), 11 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a484574a..96395323 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -28,3 +28,9 @@ flake8:
   script:
     - dnf install -y python3-flake8
     - flake8 --ignore E402,W503 --show-source gnomemusic/
+
+mypy:
+  stage: check
+  script:
+    - dnf install -y python3-mypy
+    - mypy --follow-imports=skip --ignore-missing-imports gnomemusic/coresong.py
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index eaa67fc5..a8661002 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -28,6 +28,7 @@ import gi
 gi.require_version('Grl', '0.3')
 from gi.repository import Grl, GLib, GObject
 
+from gnomemusic.application import Application
 import gnomemusic.utils as utils
 
 
@@ -55,7 +56,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
@@ -73,7 +74,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())
 
@@ -83,11 +84,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
-    def favorite(self, favorite):
+    @favorite.setter  # type: ignore
+    def favorite(self, favorite: bool) -> None:
         if not self._is_tracker:
             return
 
@@ -102,11 +103,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
-    def selected(self, value):
+    @selected.setter  # type: ignore
+    def selected(self, value: bool) -> None:
         if not self._is_tracker:
             return
 
@@ -116,7 +117,7 @@ class CoreSong(GObject.GObject):
         self._selected = value
         self._coreselection.update_selection(self, self._selected)
 
-    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()
@@ -128,7 +129,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
 
@@ -136,7 +137,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]