From 2e74d900fa0271b1e2789ff3ca5b3e7fb214e976 Mon Sep 17 00:00:00 2001 From: Arthur Taylor Date: Mon, 5 Feb 2024 23:09:09 +0100 Subject: [PATCH] Fix pyright warnings after upgrade --- flathunter/config.py | 18 +++++++++--------- flathunter/filter.py | 2 +- flathunter/hunter.py | 2 +- flathunter/web/views.py | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/flathunter/config.py b/flathunter/config.py index d82a4a9b..9c49ce4c 100644 --- a/flathunter/config.py +++ b/flathunter/config.py @@ -1,6 +1,6 @@ """Wrap configuration options as an object""" import os -from typing import Optional, Dict, Any +from typing import Optional, Dict, Any, List import json import yaml @@ -150,7 +150,7 @@ def get(self, key, value=None): """Emulate dictionary""" return self.config.get(key, value) - def _read_yaml_path(self, path, default_value=None): + def _read_yaml_path(self, path, default_value): """Resolve a dotted variable path in nested dictionaries""" config = self.config parts = path.split('.') @@ -192,18 +192,18 @@ def get_captcha_afterlogin_string(self): def database_location(self): """Return the location of the database folder""" - config_database_location = self._read_yaml_path('database_location') + config_database_location = self._read_yaml_path('database_location', None) if config_database_location is not None: return config_database_location return os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/..") - def target_urls(self): + def target_urls(self) -> List[str]: """List of target URLs for crawling""" return self._read_yaml_path('urls', []) def verbose_logging(self): """Return true if logging should be verbose""" - return self._read_yaml_path('verbose') is not None + return self._read_yaml_path('verbose', None) is not None def loop_is_active(self): """Return true if flathunter should be crawling in a loop""" @@ -248,7 +248,7 @@ def message_format(self): return config_format return self.DEFAULT_MESSAGE_FORMAT - def notifiers(self): + def notifiers(self) -> List[str]: """List of currently-active notifiers""" return self._read_yaml_path('notifiers', []) @@ -264,7 +264,7 @@ def telegram_notify_with_images(self) -> bool: def telegram_receiver_ids(self): """Static list of receiver IDs for notification messages""" - return self._read_yaml_path('telegram.receiver_ids') or [] + return self._read_yaml_path('telegram.receiver_ids', []) def mattermost_webhook_url(self): """Webhook for sending Mattermost messages""" @@ -274,7 +274,7 @@ def slack_webhook_url(self): """Webhook for sending Slack messages""" return self._read_yaml_path('slack.webhook_url', "") - def apprise_urls(self): + def apprise_urls(self) -> List[str]: """Notification URLs for Apprise""" return self._read_yaml_path('apprise', []) @@ -282,7 +282,7 @@ def _get_imagetyperz_token(self): """API Token for Imagetyperz""" return self._read_yaml_path("captcha.imagetyperz.token", "") - def get_twocaptcha_key(self): + def get_twocaptcha_key(self) -> str: """API Token for 2captcha""" return self._read_yaml_path("captcha.2captcha.api_key", "") diff --git a/flathunter/filter.py b/flathunter/filter.py index bc1b4979..bab09ca5 100644 --- a/flathunter/filter.py +++ b/flathunter/filter.py @@ -8,7 +8,7 @@ class AbstractFilter(ABC): """Abstract base class for filters""" - def is_interesting(self, _expose): + def is_interesting(self, _expose) -> bool: """Return True if an expose should be included in the output, False otherwise""" return True diff --git a/flathunter/hunter.py b/flathunter/hunter.py index 692b9996..7788ac6e 100644 --- a/flathunter/hunter.py +++ b/flathunter/hunter.py @@ -36,7 +36,7 @@ def try_crawl(searcher, url, max_pages): for searcher in self.config.searchers() for url in self.config.target_urls()]) - def hunt_flats(self, max_pages=None): + def hunt_flats(self, max_pages: None|int = None): """Crawl, process and filter exposes""" filter_set = Filter.builder() \ .read_config(self.config) \ diff --git a/flathunter/web/views.py b/flathunter/web/views.py index 5a5926a0..12037f02 100644 --- a/flathunter/web/views.py +++ b/flathunter/web/views.py @@ -5,7 +5,7 @@ from urllib import parse from flask import render_template, jsonify, request, session, redirect -from flask_api import status +from flask_api import status # type: ignore from flathunter.web import app, log from flathunter.web.util import sanitize_float