Add more type annotations
This commit is contained in:
parent
d090db380f
commit
c899eb4ee3
@ -56,9 +56,9 @@ def atomic_save(data: bytes, path: str) -> None:
|
|||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def cached_values_for(name: str) -> Generator[Dict, None, None]:
|
def cached_values_for(name: str) -> Generator[Dict[str, Any], None, None]:
|
||||||
cached_path = os.path.join(cache_dir(), name + '.json')
|
cached_path = os.path.join(cache_dir(), name + '.json')
|
||||||
cached_values: Dict = {}
|
cached_values: Dict[str, Any] = {}
|
||||||
try:
|
try:
|
||||||
with open(cached_path, 'rb') as f:
|
with open(cached_path, 'rb') as f:
|
||||||
cached_values.update(json.loads(f.read().decode('utf-8')))
|
cached_values.update(json.loads(f.read().decode('utf-8')))
|
||||||
|
|||||||
@ -10,6 +10,8 @@ from .constants import is_macos, logo_png_file
|
|||||||
from .fast_data_types import get_boss
|
from .fast_data_types import get_boss
|
||||||
from .utils import log_error
|
from .utils import log_error
|
||||||
|
|
||||||
|
NotifyImplementation = Callable[[str, str, str], None]
|
||||||
|
|
||||||
if is_macos:
|
if is_macos:
|
||||||
from .fast_data_types import cocoa_send_notification
|
from .fast_data_types import cocoa_send_notification
|
||||||
|
|
||||||
@ -59,6 +61,10 @@ else:
|
|||||||
alloc_map[alloc_id] = identifier
|
alloc_map[alloc_id] = identifier
|
||||||
|
|
||||||
|
|
||||||
|
def notify_implementation(title: str, body: str, identifier: str) -> None:
|
||||||
|
notify(title, body, identifier=identifier)
|
||||||
|
|
||||||
|
|
||||||
class NotificationCommand:
|
class NotificationCommand:
|
||||||
|
|
||||||
done: bool = True
|
done: bool = True
|
||||||
@ -167,7 +173,7 @@ def register_identifier(identifier: str, cmd: NotificationCommand, window_id: in
|
|||||||
identifier_registry.popitem(False)
|
identifier_registry.popitem(False)
|
||||||
|
|
||||||
|
|
||||||
def notification_activated(identifier: str, activated_implementation: Optional[Callable] = None) -> None:
|
def notification_activated(identifier: str, activated_implementation: Optional[Callable[[str, int, bool, bool], None]] = None) -> None:
|
||||||
if identifier == 'new-version':
|
if identifier == 'new-version':
|
||||||
from .update_check import notification_activated as do
|
from .update_check import notification_activated as do
|
||||||
do()
|
do()
|
||||||
@ -188,12 +194,12 @@ def reset_registry() -> None:
|
|||||||
id_counter = count()
|
id_counter = count()
|
||||||
|
|
||||||
|
|
||||||
def notify_with_command(cmd: NotificationCommand, window_id: int, notify: Callable = notify) -> None:
|
def notify_with_command(cmd: NotificationCommand, window_id: int, notify: NotifyImplementation = notify_implementation) -> None:
|
||||||
title = cmd.title or cmd.body
|
title = cmd.title or cmd.body
|
||||||
body = cmd.body if cmd.title else ''
|
body = cmd.body if cmd.title else ''
|
||||||
if title:
|
if title:
|
||||||
identifier = 'i' + str(next(id_counter))
|
identifier = 'i' + str(next(id_counter))
|
||||||
notify(title, body, identifier=identifier)
|
notify_implementation(title, body, identifier=identifier)
|
||||||
register_identifier(identifier, cmd, window_id)
|
register_identifier(identifier, cmd, window_id)
|
||||||
|
|
||||||
|
|
||||||
@ -202,7 +208,7 @@ def handle_notification_cmd(
|
|||||||
raw_data: str,
|
raw_data: str,
|
||||||
window_id: int,
|
window_id: int,
|
||||||
prev_cmd: NotificationCommand,
|
prev_cmd: NotificationCommand,
|
||||||
notify_implementation: Callable = notify
|
notify_implementation: NotifyImplementation = notify_implementation
|
||||||
) -> Optional[NotificationCommand]:
|
) -> Optional[NotificationCommand]:
|
||||||
if osc_code == 99:
|
if osc_code == 99:
|
||||||
cmd = merge_osc_99(prev_cmd, parse_osc_99(raw_data))
|
cmd = merge_osc_99(prev_cmd, parse_osc_99(raw_data))
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
import os
|
import os
|
||||||
from functools import lru_cache, partial, wraps
|
from functools import lru_cache, partial, wraps
|
||||||
from typing import (
|
from typing import (
|
||||||
Any, Callable, Dict, List, NamedTuple, Optional, Sequence, Tuple
|
Any, Callable, Dict, List, NamedTuple, Optional, Sequence, Tuple, Union
|
||||||
)
|
)
|
||||||
|
|
||||||
from .borders import Border, BorderColor
|
from .borders import Border, BorderColor
|
||||||
@ -119,7 +119,7 @@ class Formatter:
|
|||||||
|
|
||||||
|
|
||||||
@run_once
|
@run_once
|
||||||
def super_sub_maps() -> Tuple[dict, dict]:
|
def super_sub_maps() -> Tuple[Dict[int, Union[None, int]], Dict[int, Union[None, int]]]:
|
||||||
import string
|
import string
|
||||||
sup_table = str.maketrans(
|
sup_table = str.maketrans(
|
||||||
string.ascii_lowercase + string.ascii_uppercase + string.digits + '+-=()',
|
string.ascii_lowercase + string.ascii_uppercase + string.digits + '+-=()',
|
||||||
@ -132,7 +132,7 @@ def super_sub_maps() -> Tuple[dict, dict]:
|
|||||||
|
|
||||||
class SupSub:
|
class SupSub:
|
||||||
|
|
||||||
def __init__(self, data: dict, is_subscript: bool = False):
|
def __init__(self, data: Dict[str, Any], is_subscript: bool = False):
|
||||||
self.__data = data
|
self.__data = data
|
||||||
self.__is_subscript = is_subscript
|
self.__is_subscript = is_subscript
|
||||||
|
|
||||||
|
|||||||
@ -630,7 +630,7 @@ class Tab: # {{{
|
|||||||
for w in self:
|
for w in self:
|
||||||
yield w.as_dict(is_focused=w is active_window, is_self=w is self_window)
|
yield w.as_dict(is_focused=w is active_window, is_self=w is self_window)
|
||||||
|
|
||||||
def matches(self, field: str, pat: Pattern) -> bool:
|
def matches(self, field: str, pat: 'Pattern[str]') -> bool:
|
||||||
if field == 'id':
|
if field == 'id':
|
||||||
return bool(pat.pattern == str(self.id))
|
return bool(pat.pattern == str(self.id))
|
||||||
if field == 'title':
|
if field == 'title':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user