Skip to content

Commit

Permalink
Minor type fixes for core
Browse files Browse the repository at this point in the history
- add some missing type hints
- add a typing stub for core/info.py.in
- introduce TMP_KEYWORDS to avoid changing types
- simplify TaskTagSorter.get_first_letter to resolve a missing
  return error
  • Loading branch information
gycsaba96 authored and diegogangl committed Nov 11, 2024
1 parent 6da5c1e commit ebf8706
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
5 changes: 3 additions & 2 deletions GTG/backends/generic_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import pickle
import threading
import logging
from typing import Dict, Any

from GTG.backends.backend_signals import BackendSignals
from GTG.core.dirs import SYNC_DATA_DIR
Expand Down Expand Up @@ -66,7 +67,7 @@ class GenericBackend():
# _("Short description of the backend"),\
# }
# The complete list of constants and their meaning is given below.
_general_description = {}
_general_description: Dict[str,Any] = {}

# These are the parameters to configure a new backend of this type. A
# parameter has a name, a type and a default value.
Expand All @@ -82,7 +83,7 @@ class GenericBackend():
# GenericBackend.PARAM_DEFAULT_VALUE: 42,
# }}
# The complete list of constants and their meaning is given below.
_static_parameters = {}
_static_parameters: Dict[str,Dict[str,Any]] = {}

def initialize(self):
"""
Expand Down
17 changes: 17 additions & 0 deletions GTG/core/info.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import List

NAME: str
AUTHORS: str
COPYRIGHT: str
SHORT_DESCRIPTION: str
URL: str
CHAT_URL: str
SOURCE_CODE_URL: str
OPENHUB_URL: str
REPORT_BUG_URL: str
EMAIL: str
VERSION: str
AUTHORS_MAINTAINERS: List[str]
AUTHORS_RELEASE_CONTRIBUTORS: List[str]
ARTISTS: List[str]
DOCUMENTERS: List[str]
4 changes: 2 additions & 2 deletions GTG/core/plugins/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import inspect
import os
import logging
from typing import List
from typing import List, Tuple
from gi.repository import GLib # type: ignore[import-untyped]

from GTG.core.dirs import PLUGIN_DIRS
Expand All @@ -41,7 +41,7 @@ class Plugin():
# True if the plugin is actually loaded and running.
_active = False
missing_modules: List[str] = []
missing_dbus = []
missing_dbus: List[Tuple[str, ...]] = []

def __init__(self, info, module_paths):
"""Initialize the Plugin using a ConfigParser."""
Expand Down
9 changes: 5 additions & 4 deletions GTG/core/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

# Generate keywords and their possible translations
# They must be listed because of gettext
KEYWORDS = {
TMP_KEYWORDS = {
# Translators: Used in search parsing, no spaces, lowercased in code
"not": _("not"),
# Translators: Used in search parsing, no spaces, lowercased in code
Expand All @@ -108,9 +108,10 @@
}

# transform keywords and their translations into a list of possible commands
for key in KEYWORDS:
if " " not in KEYWORDS[key] and KEYWORDS[key].lower() != key.lower():
possible_words = [key.lower(), KEYWORDS[key].lower()]
KEYWORDS = dict()
for key in TMP_KEYWORDS:
if " " not in TMP_KEYWORDS[key] and TMP_KEYWORDS[key].lower() != key.lower():
possible_words = [key.lower(), TMP_KEYWORDS[key].lower()]
else:
possible_words = [key.lower()]
KEYWORDS[key] = possible_words
Expand Down
6 changes: 2 additions & 4 deletions GTG/core/sorters.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,8 @@ class TaskTagSorter(ReversibleSorter):
def get_first_letter(self, tags) -> str:
"""Get first letter of the first tag in a set of tags."""

# Fastest way to get the first item
# on a set in Python
for t in tags:
return t.name[0]
return next(iter(tags)).name[0]


def do_compare(self, a, b) -> Gtk.Ordering:

Expand Down

0 comments on commit ebf8706

Please sign in to comment.