From eb8093d25f8fb10a9a48166885a6885459110e7f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philipp=20H=C3=B6rist?= <philipp@hoerist.com>
Date: Fri, 21 Sep 2018 15:46:25 +0200
Subject: [PATCH] Add annotations

- Remove some unused vars from app
---
 gajim/accounts_window.py     |  4 ---
 gajim/common/app.py          | 62 +++++++++++++++++++++++-------------
 gajim/common/types.py        |  7 ++++
 gajim/config.py              |  2 --
 gajim/gtk/account_wizard.py  |  2 --
 gajim/gtkexcepthook.py       |  5 ++-
 gajim/gui_interface.py       |  2 --
 gajim/plugins/gajimplugin.py | 29 +++++++++++------
 test/lib/gajim_mocks.py      |  2 --
 9 files changed, 69 insertions(+), 46 deletions(-)

diff --git a/gajim/accounts_window.py b/gajim/accounts_window.py
index fd924f8481..8d6c00db6e 100644
--- a/gajim/accounts_window.py
+++ b/gajim/accounts_window.py
@@ -258,10 +258,8 @@ class AccountsWindow(Gtk.ApplicationWindow):
                 'accounts', account, 'name')
         app.block_signed_in_notifications[account] = True
         app.sleeper_state[account] = 'off'
-        app.encrypted_chats[account] = []
         app.last_message_time[account] = {}
         app.status_before_autoaway[account] = ''
-        app.transport_avatar[account] = {}
         app.gajim_optional_features[account] = []
         app.caps_hash[account] = ''
         helpers.update_optional_features(account)
@@ -292,10 +290,8 @@ class AccountsWindow(Gtk.ApplicationWindow):
         del app.to_be_removed[account]
         del app.newly_added[account]
         del app.sleeper_state[account]
-        del app.encrypted_chats[account]
         del app.last_message_time[account]
         del app.status_before_autoaway[account]
-        del app.transport_avatar[account]
         del app.gajim_optional_features[account]
         del app.caps_hash[account]
         if len(app.connections) >= 2:
diff --git a/gajim/common/app.py b/gajim/common/app.py
index 27a0364839..eefed71d0f 100644
--- a/gajim/common/app.py
+++ b/gajim/common/app.py
@@ -24,6 +24,9 @@
 # You should have received a copy of the GNU General Public License
 # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
 
+from typing import Dict  # pylint: disable=unused-import
+from typing import List  # pylint: disable=unused-import
+
 import os
 import sys
 import logging
@@ -68,53 +71,66 @@ css_config = None
 
 os_info = None # used to cache os information
 
-transport_type = {} # list the type of transport
+transport_type = {}  # type: Dict[str, str]
 
-last_message_time = {} # list of time of the latest incoming message
-                       # {acct1: {jid1: time1, jid2: time2}, }
-encrypted_chats = {}   # list of encrypted chats {acct1: [jid1, jid2], ..}
+# dict of time of the latest incoming message per jid
+# {acct1: {jid1: time1, jid2: time2}, }
+last_message_time = {}  # type: Dict[str, Dict[str, float]]
 
 contacts = LegacyContactsAPI()
-gc_connected = {}    # tell if we are connected to the room or not
-                     # {acct: {room_jid: True}}
-gc_passwords = {}    # list of the pass required to enter a room
-                     # {room_jid: password}
-automatic_rooms = {} # list of rooms that must be automaticaly configured
-                     # and for which we have a list of invities
-                     #{account: {room_jid: {'invities': []}}}
-
-groups = {} # list of groups
-newly_added = {} # list of contacts that has just signed in
-to_be_removed = {} # list of contacts that has just signed out
+
+# tell if we are connected to the room or not
+# {acct: {room_jid: True}}
+gc_connected = {}  # type: Dict[str, Dict[str, bool]]
+
+# dict of the pass required to enter a room
+# {room_jid: password}
+gc_passwords = {}  # type: Dict[str, str]
+
+# dict of rooms that must be automaticaly configured
+# and for which we have a list of invities
+# {account: {room_jid: {'invities': []}}}
+automatic_rooms = {}  # type: Dict[str, Dict[str, Dict[str, List[str]]]]
+
+ # dict of groups, holds if they are expanded or not
+groups = {}  # type: Dict[str, Dict[str, Dict[str, bool]]]
+
+# list of contacts that has just signed in
+newly_added = {}  # type: Dict[str, List[str]]
+
+# list of contacts that has just signed out
+to_be_removed = {}  # type: Dict[str, List[str]]
 
 events = Events()
 
 notification = None
 
-nicks = {} # list of our nick names in each account
+# list of our nick names in each account
+nicks = {}  # type: Dict[str, str]
+
 # should we block 'contact signed in' notifications for this account?
 # this is only for the first 30 seconds after we change our show
 # to something else than offline
 # can also contain account/transport_jid to block notifications for contacts
 # from this transport
 block_signed_in_notifications = {}
-con_types = {} # type of each connection (ssl, tls, tcp, ...)
 
-sleeper_state = {} # whether we pass auto away / xa or not
+ # type of each connection (ssl, tls, tcp, ...)
+con_types = {}  # type: Dict[str, Optional[str]]
+
+# whether we pass auto away / xa or not
 #'off': don't use sleeper for this account
 #'online': online and use sleeper
 #'autoaway': autoaway and use sleeper
 #'autoxa': autoxa and use sleeper
-status_before_autoaway = {}
+sleeper_state = {}  # type: Dict[str, str]
 
-# jid of transport contacts for which we need to ask avatar when transport will
-# be online
-transport_avatar = {} # {transport_jid: [jid_list]}
+status_before_autoaway = {}  # type: Dict[str, str]
 
 # Is Gnome configured to activate on single click ?
 single_click = False
 SHOW_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
-        'invisible', 'error']
+             'invisible', 'error']
 
 # zeroconf account name
 ZEROCONF_ACC_NAME = 'Local'
diff --git a/gajim/common/types.py b/gajim/common/types.py
index 08b29eacf2..7d467add30 100644
--- a/gajim/common/types.py
+++ b/gajim/common/types.py
@@ -32,6 +32,7 @@ if TYPE_CHECKING:
     from gajim.common.zeroconf.connection_zeroconf import ConnectionZeroconf
     from gajim.common.contacts import Contact
     from gajim.common.contacts import GC_Contact
+    from gajim.common.nec import NetworkEvent
 
 ConnectionT = Union['Connection', 'ConnectionZeroconf']
 ContactT = Union['Contact', 'GC_Contact']
@@ -44,3 +45,9 @@ PEPHandlersDict = Dict[str, List[PEPNotifyCallback]]
 
 # Configpaths
 PathTuple = Tuple[Optional[PathLocation], str, Optional[PathType]]
+
+# Plugins
+PluginExtensionPoints = Dict[str, Tuple[Optional[Callable[..., None]],
+                                        Optional[Callable[..., None]]]]
+EventHandlersDict = Dict[str, Tuple[int, Callable[['NetworkEvent'], Optional[bool]]]]
+PluginEvents = List['NetworkEvent']
diff --git a/gajim/config.py b/gajim/config.py
index 84376c2f9e..0062d119aa 100644
--- a/gajim/config.py
+++ b/gajim/config.py
@@ -674,10 +674,8 @@ class RemoveAccountWindow:
             del app.to_be_removed[self.account]
             del app.newly_added[self.account]
             del app.sleeper_state[self.account]
-            del app.encrypted_chats[self.account]
             del app.last_message_time[self.account]
             del app.status_before_autoaway[self.account]
-            del app.transport_avatar[self.account]
             del app.gajim_optional_features[self.account]
             del app.caps_hash[self.account]
         if len(app.connections) >= 2: # Do not merge accounts if only one exists
diff --git a/gajim/gtk/account_wizard.py b/gajim/gtk/account_wizard.py
index 4153dceb3c..e8c37ddaab 100644
--- a/gajim/gtk/account_wizard.py
+++ b/gajim/gtk/account_wizard.py
@@ -582,10 +582,8 @@ class AccountCreationWizard:
         app.nicks[self.account] = config['name']
         app.block_signed_in_notifications[self.account] = True
         app.sleeper_state[self.account] = 'off'
-        app.encrypted_chats[self.account] = []
         app.last_message_time[self.account] = {}
         app.status_before_autoaway[self.account] = ''
-        app.transport_avatar[self.account] = {}
         app.gajim_optional_features[self.account] = []
         app.caps_hash[self.account] = ''
         helpers.update_optional_features(self.account)
diff --git a/gajim/gtkexcepthook.py b/gajim/gtkexcepthook.py
index 021d0da307..5c8dd17f8b 100644
--- a/gajim/gtkexcepthook.py
+++ b/gajim/gtkexcepthook.py
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
 
+from typing import cast
+
 import sys
 import os
 import traceback
@@ -40,7 +42,8 @@ if __name__ == '__main__':
     glade_file = os.path.join('data', 'gui', 'exception_dialog.ui')
 else:
     from gajim.common import configpaths
-    glade_file = os.path.join(configpaths.get('GUI'), 'exception_dialog.ui')
+    gui_path = cast(str, configpaths.get('GUI'))
+    glade_file = os.path.join(gui_path, 'exception_dialog.ui')
 
 
 _exception_in_progress = threading.Lock()
diff --git a/gajim/gui_interface.py b/gajim/gui_interface.py
index f0f7800419..48780dae17 100644
--- a/gajim/gui_interface.py
+++ b/gajim/gui_interface.py
@@ -2714,10 +2714,8 @@ class Interface:
             app.nicks[a] = app.config.get_per('accounts', a, 'name')
             app.block_signed_in_notifications[a] = True
             app.sleeper_state[a] = 0
-            app.encrypted_chats[a] = []
             app.last_message_time[a] = {}
             app.status_before_autoaway[a] = ''
-            app.transport_avatar[a] = {}
             app.gajim_optional_features[a] = []
             app.caps_hash[a] = ''
 
diff --git a/gajim/plugins/gajimplugin.py b/gajim/plugins/gajimplugin.py
index 593a5ddea5..d6824d6e0d 100644
--- a/gajim/plugins/gajimplugin.py
+++ b/gajim/plugins/gajimplugin.py
@@ -21,15 +21,25 @@ Base class for implementing plugin.
 :license: GPL
 '''
 
+from typing import List  # pylint: disable=W0611
+from typing import Tuple  # pylint: disable=W0611
+from typing import Dict  # pylint: disable=W0611
+from typing import Any  # pylint: disable=W0611
+
 import os
 import locale
+import logging
+import pickle
 
 from gajim.common import configpaths
+from gajim.common.types import PluginExtensionPoints  # pylint: disable=W0611
+from gajim.common.types import EventHandlersDict  # pylint: disable=W0611
+from gajim.common.types import PluginEvents  # pylint: disable=W0611
 
 from gajim.plugins.helpers import log_calls, log
 from gajim.plugins.gui import GajimPluginConfigDialog
 
-import logging
+
 log = logging.getLogger('gajim.p.plugin')
 
 
@@ -86,7 +96,7 @@ class GajimPlugin:
 
     :todo: should be allow rich text here (like HTML or reStructuredText)?
     '''
-    authors = []
+    authors = []  # type: List[str]
     '''
     Plugin authors.
 
@@ -104,7 +114,7 @@ class GajimPlugin:
     :todo: should we check whether provided string is valid URI? (Maybe
     using 'property')
     '''
-    gui_extension_points = {}
+    gui_extension_points = {}  # type: PluginExtensionPoints
     '''
     Extension points that plugin wants to connect with and handlers to be used.
 
@@ -118,7 +128,7 @@ class GajimPlugin:
     or when extpoint is destroyed and plugin is activate (eg. chat window
     closed).
     '''
-    config_default_values = {}
+    config_default_values = {}  # type: Dict[str, Tuple[Any, str]]
     '''
     Default values for keys that should be stored in plug-in config.
 
@@ -132,7 +142,7 @@ class GajimPlugin:
 
     :type: {} of 2-element tuples
     '''
-    events_handlers = {}
+    events_handlers = {}  # type: EventHandlersDict
     '''
     Dictionary with events handlers.
 
@@ -143,7 +153,7 @@ class GajimPlugin:
 
     :type: {} with 2-element tuples
     '''
-    events = []
+    events = []  # type: PluginEvents
     '''
     New network event classes to be registered in Network Events Controller.
 
@@ -152,7 +162,7 @@ class GajimPlugin:
     '''
 
     @log_calls('GajimPlugin')
-    def __init__(self):
+    def __init__(self) -> None:
         self.config = GajimPluginConfig(self)
         '''
         Plug-in configuration dictionary.
@@ -168,11 +178,11 @@ class GajimPlugin:
         self.init()
 
     @log_calls('GajimPlugin')
-    def save_config(self):
+    def save_config(self) -> None:
         self.config.save()
 
     @log_calls('GajimPlugin')
-    def load_config(self):
+    def load_config(self) -> None:
         self.config.load()
 
     def __eq__(self, plugin):
@@ -203,7 +213,6 @@ class GajimPlugin:
     def deactivate(self):
         pass
 
-import pickle
 
 class GajimPluginConfig():
     @log_calls('GajimPluginConfig')
diff --git a/test/lib/gajim_mocks.py b/test/lib/gajim_mocks.py
index 6dabcb2903..5f03d835b1 100644
--- a/test/lib/gajim_mocks.py
+++ b/test/lib/gajim_mocks.py
@@ -35,10 +35,8 @@ class MockConnection(Mock, ConnectionHandlers):
         app.nicks[account] = app.config.get_per('accounts', account, 'name')
         app.block_signed_in_notifications[account] = True
         app.sleeper_state[account] = 0
-        app.encrypted_chats[account] = []
         app.last_message_time[account] = {}
         app.status_before_autoaway[account] = ''
-        app.transport_avatar[account] = {}
         app.gajim_optional_features[account] = []
         app.caps_hash[account] = ''
 
-- 
GitLab