From 2f58a016c36071d1951f7d6c4a923d40e5ee6387 Mon Sep 17 00:00:00 2001 From: weissle <2016301500298@whu.edu.cn> Date: Tue, 14 Mar 2023 13:59:46 +0800 Subject: [PATCH] fix: Backward compatibility with python3.8 and python3.9 --- dooit/ui/widgets/help_menu.py | 2 +- dooit/ui/widgets/simple_input.py | 10 +++++----- dooit/ui/widgets/sort_options.py | 6 +++--- dooit/ui/widgets/tree.py | 2 +- dooit/utils/keybinder.py | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dooit/ui/widgets/help_menu.py b/dooit/ui/widgets/help_menu.py index 328c3a06..d243f5c8 100644 --- a/dooit/ui/widgets/help_menu.py +++ b/dooit/ui/widgets/help_menu.py @@ -57,7 +57,7 @@ def convert_to_row(bindings: Dict): def generate_kb_table( - kb: dict[str, str], topic: str, notes: list[str] = [] + kb: Dict[str, str], topic: str, notes: List[str] = [] ) -> RenderableType: """ Generate Table for modes diff --git a/dooit/ui/widgets/simple_input.py b/dooit/ui/widgets/simple_input.py index 8883e884..b2d9e068 100644 --- a/dooit/ui/widgets/simple_input.py +++ b/dooit/ui/widgets/simple_input.py @@ -1,5 +1,5 @@ import pyperclip -from typing import Any, Literal +from typing import Any, Literal, Optional, List, Tuple from rich.style import StyleType from rich.text import Text, TextType from rich.box import Box @@ -20,15 +20,15 @@ class SimpleInput(Widget): def __init__( self, - name: str | None = None, + name: Optional[str] = None, value: Any = "", title: TextType = "", title_align: AlignMethod = "center", border_style: StyleType = "blue", - box: Box | None = None, + box: Optional[Box] = None, placeholder: Text = Text("", style="dim white"), password: bool = False, - list: tuple[Literal["blacklist", "whitelist"], list[str]] = ("blacklist", []), + list: Tuple[Literal["blacklist", "whitelist"], List[str]] = ("blacklist", []), ) -> None: super().__init__(name=name) self.title = title @@ -107,7 +107,7 @@ def _is_allowed(self, text: str) -> bool: return True - async def _insert_text(self, text: str | None = None) -> None: + async def _insert_text(self, text: Optional[str] = None) -> None: """ Inserts text where the cursor is """ diff --git a/dooit/ui/widgets/sort_options.py b/dooit/ui/widgets/sort_options.py index 4cd83d10..6de8db32 100644 --- a/dooit/ui/widgets/sort_options.py +++ b/dooit/ui/widgets/sort_options.py @@ -1,4 +1,4 @@ -from typing import Optional, Type +from typing import Optional, Type, List from rich.align import Align from rich.box import HEAVY from rich.console import RenderableType @@ -20,8 +20,8 @@ class SortOptions(Widget): def __init__( self, - name: str | None = None, - options: list[str] = [], + name: Optional[str] = None, + options: List[str] = [], parent_widget: Optional[Widget] = None, style_unfocused: StyleType = "white", style_focused: StyleType = "bold reverse green ", diff --git a/dooit/ui/widgets/tree.py b/dooit/ui/widgets/tree.py index 8ca7e6ea..4bdaf3ea 100644 --- a/dooit/ui/widgets/tree.py +++ b/dooit/ui/widgets/tree.py @@ -49,7 +49,7 @@ class TreeList(Widget): def __init__( self, - name: str | None = None, + name: Optional[str] = None, model: Manager = manager, ) -> None: super().__init__(name=name) diff --git a/dooit/utils/keybinder.py b/dooit/utils/keybinder.py index 533ae0d3..d1b4e720 100644 --- a/dooit/utils/keybinder.py +++ b/dooit/utils/keybinder.py @@ -1,8 +1,8 @@ from collections import defaultdict from typing import DefaultDict, Dict, List, Optional, Union from dooit.utils.conf_reader import Config - -configured_keys = Config().get("keybindings") +from copy import deepcopy +customed_keys = Config().get("keybindings") class Bind: @@ -53,8 +53,8 @@ def __init__(self, func_name: str, params: List[str]) -> None: "decrease urgency": ["-", "_"], "exit": "", } - -configured_keys = DEFAULTS | configured_keys +configured_keys = deepcopy(DEFAULTS) +configured_keys.update(customed_keys) class KeyBinder: