commit b81a9d8562dcda0480b4cc5524f7fb3245749245
parent 0736f2d63ce2194a237500cf9181e684aa897f21
Author: Isak Lindhé <isak.e.lindhe@gmail.com>
Date: Wed, 10 Apr 2019 22:17:07 +0200
type hints everywhere possible
Diffstat:
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/txtv/config.py b/txtv/config.py
@@ -11,7 +11,7 @@ CONFIG_DEFAULT_VALUES = {
},
}
-def get_config(config_path: Path = CONFIG_DEFAULT_PATH):
+def get_config(config_path: Path = CONFIG_DEFAULT_PATH) -> configparser.ConfigParser:
cfg = configparser.ConfigParser()
cfg.read_dict(CONFIG_DEFAULT_VALUES)
if config_path and config_path.exists():
diff --git a/txtv/listing.py b/txtv/listing.py
@@ -4,7 +4,7 @@ from txtv.txtv import Page
from pprint import pprint
-def get_page_loop(start_num: int, pattern):
+def get_page_loop(start_num: int, pattern: str) -> list:
pages = [Page(start_num)]
while True:
match = re.search(pattern, pages[-1].subpages[0].get_text())
@@ -14,7 +14,7 @@ def get_page_loop(start_num: int, pattern):
return pages
-def is_content_entry(tag: bs4.element.Tag):
+def is_content_entry(tag: bs4.element.Tag) -> bool:
# children = [
# c for c in tag.children
# if not (isinstance(c, str) and re.match(r' +', c))
@@ -62,7 +62,7 @@ def parse_content_entry(line: str) -> tuple:
return None
-def list_all_articles():
+def list_all_articles() -> list:
full_listing = []
for nbr in [101, 104]:
pages = get_page_loop(nbr, r'Fler rubriker ([0-9]{3})')
diff --git a/txtv/txtv.py b/txtv/txtv.py
@@ -25,7 +25,7 @@ class Page:
except rq.exceptions.RequestException as e:
err(f"Could not get '{url}'.")
- def show(self, subpages=None):
+ def show(self, subpages=None) -> str:
"""Prints the page contained by the specified tag in color."""
out = ""
for page in subpages or self.subpages:
@@ -63,7 +63,7 @@ def validate_page_nbr(arg: str) -> int:
return num
-def match_command(arg: str, interactive=False):
+def match_command(arg: str, interactive: bool=False) -> tuple:
for cmd in commands:
if interactive or 'interactive_only' not in cmd or not cmd['interactive_only']:
m = re.fullmatch(cmd['pattern'], arg)
@@ -72,7 +72,7 @@ def match_command(arg: str, interactive=False):
return None, None
-def interactive(start_page: Page, cfg):
+def interactive(start_page: Page, cfg: configparser.ConfigParser):
print(start_page.show())
state = dict(page=start_page)
while True:
@@ -97,7 +97,7 @@ def interactive(start_page: Page, cfg):
#####################
-def cmd_help(**kwargs):
+def cmd_help(**kwargs) -> str:
out = 'commands:\n'
for cmd in commands:
if 'help' in cmd:
@@ -115,17 +115,17 @@ def cmd_help(**kwargs):
return out
-def cmd_next(state, **kwargs):
+def cmd_next(state: dict, **kwargs) -> str:
state['page'] = state['page'].next_page()
return state['page'].show()
-def cmd_prev(state, **kwargs):
+def cmd_prev(state: dict, **kwargs) -> str:
state['page'] = state['page'].prev_page()
return state['page'].show()
-def cmd_list(**kwargs):
+def cmd_list(**kwargs) -> str:
from txtv.listing import list_all_articles
out = ''
articles = list_all_articles()
@@ -136,7 +136,7 @@ def cmd_list(**kwargs):
return out
-def cmd_page(match, state=None, cfg: configparser.ConfigParser=None, **kwargs):
+def cmd_page(match, state: dict=None, cfg: configparser.ConfigParser=None, **kwargs) -> str:
try:
num = validate_page_nbr(match.group(0))
except ValueError as e: