From 9eba12cba5641d6a0b988038694cbc2dd52800c5 Mon Sep 17 00:00:00 2001 From: Scott Date: Mon, 31 Jan 2022 21:38:46 -0800 Subject: [PATCH] Myre mypy fixes. --- config.py | 11 ++++++----- google_assistant.py | 6 +++--- string_utils.py | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/config.py b/config.py index f543b0a..588b7e0 100644 --- a/config.py +++ b/config.py @@ -80,8 +80,8 @@ from typing import Any, Dict, List, Optional saved_messages: List[str] = [] # Make a copy of the original program arguments. -program_name = os.path.basename(sys.argv[0]) -original_argv = [arg for arg in sys.argv] +program_name: str = os.path.basename(sys.argv[0]) +original_argv: List[str] = [arg for arg in sys.argv] # A global parser that we will collect arguments into. @@ -101,7 +101,7 @@ config_parse_called = False # It is also this variable that modules use to access parsed arguments. # This is the data that is most interesting to our callers; it will hold # the configuration result. -config = {} +config: Dict[str, Any] = {} # It would be really nice if this shit worked from interactive python @@ -154,11 +154,12 @@ def is_flag_already_in_argv(var: str): def reorder_arg_action_groups(entry_module: Optional[str]): + global program_name, args reordered_action_groups = [] for group in args._action_groups: - if entry_module is not None and entry_module in group.title: + if entry_module is not None and entry_module in group.title: # type: ignore reordered_action_groups.append(group) - elif program_name in group.title: + elif program_name in group.title: # type: ignore reordered_action_groups.append(group) else: reordered_action_groups.insert(0, group) diff --git a/google_assistant.py b/google_assistant.py index b92f443..0af4fa9 100644 --- a/google_assistant.py +++ b/google_assistant.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 import logging -from typing import NamedTuple import sys +from typing import NamedTuple, Optional import warnings import requests @@ -36,7 +36,7 @@ class GoogleResponse(NamedTuple): success: bool response: str audio_url: str - audio_transcription: str + audio_transcription: Optional[str] # None if not available. def __repr__(self): return f""" @@ -67,7 +67,7 @@ def ask_google(cmd: str, *, recognize_speech=True) -> GoogleResponse: success = False response = "" audio = "" - audio_transcription = "" + audio_transcription: Optional[str] = "" if r.status_code == 200: j = r.json() success = bool(j["success"]) diff --git a/string_utils.py b/string_utils.py index 991793d..9a20466 100644 --- a/string_utils.py +++ b/string_utils.py @@ -1095,7 +1095,7 @@ def to_date(in_str: str) -> Optional[datetime.date]: """ Parses a date string. See DateParser docs for details. """ - import dateparse.dateparse_utils as dp + import dateparse.dateparse_utils as dp # type: ignore try: d = dp.DateParser() -- 2.45.2