Skip to content

Commit

Permalink
fix: typing
Browse files Browse the repository at this point in the history
  • Loading branch information
kazhala committed Jun 27, 2022
1 parent e69ab82 commit 6915996
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 136 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 21.7b0
rev: 22.3.0
hooks:
- id: black
files: InquirerPy
Expand All @@ -13,7 +13,7 @@ repos:
additional_dependencies: [toml]

- repo: https://github.com/pycqa/isort
rev: 5.9.3
rev: 5.10.1
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
Expand Down
17 changes: 10 additions & 7 deletions InquirerPy/base/complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
from prompt_toolkit.filters.base import Condition, FilterOrBool
from prompt_toolkit.key_binding.key_bindings import KeyHandlerCallable
from prompt_toolkit.keys import Keys
from prompt_toolkit.validation import Validator

from InquirerPy.base.simple import BaseSimplePrompt
from InquirerPy.enum import INQUIRERPY_KEYBOARD_INTERRUPT
from InquirerPy.utils import InquirerPySessionResult, InquirerPyStyle
from InquirerPy.utils import (
InquirerPySessionResult,
InquirerPyStyle,
InquirerPyValidate,
)


@dataclass
Expand Down Expand Up @@ -50,22 +53,22 @@ class BaseComplexPrompt(BaseSimplePrompt):
def __init__(
self,
message: Union[str, Callable[[InquirerPySessionResult], str]],
style: InquirerPyStyle = None,
style: Optional[InquirerPyStyle] = None,
border: bool = False,
vi_mode: bool = False,
qmark: str = "?",
amark: str = "?",
instruction: str = "",
long_instruction: str = "",
transformer: Callable[[Any], Any] = None,
filter: Callable[[Any], Any] = None,
validate: Union[Callable[[Any], bool], Validator] = None,
transformer: Optional[Callable[[Any], Any]] = None,
filter: Optional[Callable[[Any], Any]] = None,
validate: Optional[InquirerPyValidate] = None,
invalid_message: str = "Invalid input",
wrap_lines: bool = True,
raise_keyboard_interrupt: bool = True,
mandatory: bool = True,
mandatory_message: str = "Mandatory prompt",
session_result: InquirerPySessionResult = None,
session_result: Optional[InquirerPySessionResult] = None,
) -> None:
super().__init__(
message=message,
Expand Down
2 changes: 1 addition & 1 deletion InquirerPy/base/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(
choices: InquirerPyListChoices,
default: Any = None,
multiselect: bool = False,
session_result: InquirerPySessionResult = None,
session_result: Optional[InquirerPySessionResult] = None,
) -> None:
self._session_result = session_result or {}
self._selected_choice_index: int = 0
Expand Down
19 changes: 10 additions & 9 deletions InquirerPy/base/list.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
"""Contains the base class :class:`.BaseListPrompt` which can be used to create a prompt involving choices."""
from abc import abstractmethod
from typing import Any, Callable, List, Union
from typing import Any, Callable, List, Optional

from prompt_toolkit.filters.base import Condition
from prompt_toolkit.keys import Keys
from prompt_toolkit.validation import Validator

from InquirerPy.base.complex import BaseComplexPrompt
from InquirerPy.base.control import InquirerPyUIListControl
from InquirerPy.separator import Separator
from InquirerPy.utils import (
InquirerPyKeybindings,
InquirerPyMessage,
InquirerPySessionResult,
InquirerPyStyle,
InquirerPyValidate,
)


Expand All @@ -30,26 +31,26 @@ class BaseListPrompt(BaseComplexPrompt):

def __init__(
self,
message: Union[str, Callable[[InquirerPySessionResult], str]],
style: InquirerPyStyle = None,
message: InquirerPyMessage,
style: Optional[InquirerPyStyle] = None,
vi_mode: bool = False,
qmark: str = "?",
amark: str = "?",
instruction: str = "",
long_instruction: str = "",
border: bool = False,
transformer: Callable[[Any], Any] = None,
filter: Callable[[Any], Any] = None,
validate: Union[Callable[[Any], bool], Validator] = None,
transformer: Optional[Callable[[Any], Any]] = None,
filter: Optional[Callable[[Any], Any]] = None,
validate: Optional[InquirerPyValidate] = None,
invalid_message: str = "Invalid input",
multiselect: bool = False,
keybindings: InquirerPyKeybindings = None,
keybindings: Optional[InquirerPyKeybindings] = None,
cycle: bool = True,
wrap_lines: bool = True,
raise_keyboard_interrupt: bool = True,
mandatory: bool = True,
mandatory_message: str = "Mandatory prompt",
session_result: InquirerPySessionResult = None,
session_result: Optional[InquirerPySessionResult] = None,
) -> None:
super().__init__(
message=message,
Expand Down
12 changes: 6 additions & 6 deletions InquirerPy/base/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ class BaseSimplePrompt(ABC):
def __init__(
self,
message: InquirerPyMessage,
style: InquirerPyStyle = None,
style: Optional[InquirerPyStyle] = None,
vi_mode: bool = False,
qmark: str = "?",
amark: str = "?",
instruction: str = "",
validate: InquirerPyValidate = None,
validate: Optional[InquirerPyValidate] = None,
invalid_message: str = "Invalid input",
transformer: Callable[[Any], Any] = None,
filter: Callable[[Any], Any] = None,
transformer: Optional[Callable[[Any], Any]] = None,
filter: Optional[Callable[[Any], Any]] = None,
default: Any = "",
wrap_lines: bool = True,
raise_keyboard_interrupt: bool = True,
mandatory: bool = True,
mandatory_message: str = "Mandatory prompt",
session_result: InquirerPySessionResult = None,
session_result: Optional[InquirerPySessionResult] = None,
) -> None:
self._mandatory = mandatory
self._mandatory_message = mandatory_message
Expand Down Expand Up @@ -315,7 +315,7 @@ async def _run_async(self) -> Any:
"""
pass

def execute(self, raise_keyboard_interrupt: bool = None) -> Any:
def execute(self, raise_keyboard_interrupt: Optional[bool] = None) -> Any:
"""Run the prompt and get the result.
Args:
Expand Down
4 changes: 2 additions & 2 deletions InquirerPy/containers/spinner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Use library such as `yaspin <https://github.com/pavdmyt/yaspin>`_ if you need a plain spinner.
"""
import asyncio
from typing import TYPE_CHECKING, Callable, List, NamedTuple, Tuple, Union
from typing import TYPE_CHECKING, Callable, List, NamedTuple, Optional, Tuple, Union

from prompt_toolkit.filters.utils import to_filter
from prompt_toolkit.layout.containers import ConditionalContainer, Window
Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(
self,
loading: "Filter",
redraw: Callable[[], None],
pattern: Union[List[str], SPINNERS] = None,
pattern: Optional[Union[List[str], SPINNERS]] = None,
delay: float = 0.1,
text: str = "",
) -> None:
Expand Down
10 changes: 6 additions & 4 deletions InquirerPy/containers/validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Module contains :class:`.ValidationWindow` which can be used to display error."""

from typing import Optional

from prompt_toolkit.filters.base import FilterOrBool
from prompt_toolkit.formatted_text.base import AnyFormattedText
from prompt_toolkit.layout.containers import ConditionalContainer, Float, Window
Expand Down Expand Up @@ -41,10 +43,10 @@ def __init__(
self,
invalid_message: AnyFormattedText,
filter: FilterOrBool,
left: int = None,
right: int = None,
bottom: int = None,
top: int = None,
left: Optional[int] = None,
right: Optional[int] = None,
bottom: Optional[int] = None,
top: Optional[int] = None,
**kwargs
) -> None:
super().__init__(
Expand Down
16 changes: 8 additions & 8 deletions InquirerPy/prompts/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def __init__(
message: InquirerPyMessage,
choices: InquirerPyListChoices,
default: Any = None,
style: InquirerPyStyle = None,
style: Optional[InquirerPyStyle] = None,
vi_mode: bool = False,
qmark: str = "?",
amark: str = "?",
Expand All @@ -175,20 +175,20 @@ def __init__(
border: bool = False,
instruction: str = "",
long_instruction: str = "",
transformer: Callable[[Any], Any] = None,
filter: Callable[[Any], Any] = None,
height: Union[int, str] = None,
max_height: Union[int, str] = None,
validate: InquirerPyValidate = None,
transformer: Optional[Callable[[Any], Any]] = None,
filter: Optional[Callable[[Any], Any]] = None,
height: Optional[Union[int, str]] = None,
max_height: Optional[Union[int, str]] = None,
validate: Optional[InquirerPyValidate] = None,
invalid_message: str = "Invalid input",
keybindings: InquirerPyKeybindings = None,
keybindings: Optional[InquirerPyKeybindings] = None,
show_cursor: bool = True,
cycle: bool = True,
wrap_lines: bool = True,
raise_keyboard_interrupt: bool = True,
mandatory: bool = True,
mandatory_message: str = "Mandatory prompt",
session_result: InquirerPySessionResult = None,
session_result: Optional[InquirerPySessionResult] = None,
) -> None:
self.content_control = InquirerPyCheckboxControl(
choices=choices,
Expand Down
19 changes: 10 additions & 9 deletions InquirerPy/prompts/confirm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Module contains the class to create a confirm prompt."""
from typing import TYPE_CHECKING, Any, Callable, List, Tuple
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Tuple

from prompt_toolkit.buffer import ValidationState
from prompt_toolkit.keys import Keys
Expand All @@ -18,6 +18,7 @@

if TYPE_CHECKING:
from prompt_toolkit.input.base import Input
from prompt_toolkit.key_binding.key_processor import KeyPressEvent
from prompt_toolkit.output.base import Output

__all__ = ["ConfirmPrompt"]
Expand Down Expand Up @@ -72,25 +73,25 @@ class ConfirmPrompt(BaseSimplePrompt):
def __init__(
self,
message: InquirerPyMessage,
style: InquirerPyStyle = None,
style: Optional[InquirerPyStyle] = None,
default: InquirerPyDefault = False,
vi_mode: bool = False,
qmark: str = "?",
amark: str = "?",
instruction: str = "",
long_instruction: str = "",
transformer: Callable[[bool], Any] = None,
filter: Callable[[bool], Any] = None,
keybindings: InquirerPyKeybindings = None,
transformer: Optional[Callable[[bool], Any]] = None,
filter: Optional[Callable[[bool], Any]] = None,
keybindings: Optional[InquirerPyKeybindings] = None,
wrap_lines: bool = True,
confirm_letter: str = "y",
reject_letter: str = "n",
raise_keyboard_interrupt: bool = True,
mandatory: bool = True,
mandatory_message: str = "Mandatory prompt",
session_result: InquirerPySessionResult = None,
input: "Input" = None,
output: "Output" = None,
session_result: Optional[InquirerPySessionResult] = None,
input: Optional["Input"] = None,
output: Optional["Output"] = None,
) -> None:
vi_mode = False
super().__init__(
Expand Down Expand Up @@ -165,7 +166,7 @@ def _handle_confirm(self, event) -> None:
self.status["result"] = True
event.app.exit(result=True)

def _handle_enter(self, event) -> None:
def _handle_enter(self, event: "KeyPressEvent") -> None:
self.status["answered"] = True
self.status["result"] = self._default
event.app.exit(result=self._default)
Expand Down
20 changes: 10 additions & 10 deletions InquirerPy/prompts/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,35 +274,35 @@ def __init__(
message: InquirerPyMessage,
choices: InquirerPyListChoices,
default: InquirerPyDefault = "",
style: InquirerPyStyle = None,
style: Optional[InquirerPyStyle] = None,
vi_mode: bool = False,
qmark: str = "?",
amark: str = "?",
pointer: str = " ",
separator: str = ") ",
help_msg: str = "Help, list all choices",
expand_help: ExpandHelp = None,
expand_help: Optional[ExpandHelp] = None,
expand_pointer: str = "%s " % INQUIRERPY_POINTER_SEQUENCE,
instruction: str = "",
long_instruction: str = "",
transformer: Callable[[Any], Any] = None,
filter: Callable[[Any], Any] = None,
height: Union[int, str] = None,
max_height: Union[int, str] = None,
transformer: Optional[Callable[[Any], Any]] = None,
filter: Optional[Callable[[Any], Any]] = None,
height: Optional[Union[int, str]] = None,
max_height: Optional[Union[int, str]] = None,
multiselect: bool = False,
marker: str = INQUIRERPY_POINTER_SEQUENCE,
marker_pl: str = " ",
border: bool = False,
validate: InquirerPyValidate = None,
validate: Optional[InquirerPyValidate] = None,
invalid_message: str = "Invalid input",
keybindings: InquirerPyKeybindings = None,
keybindings: Optional[InquirerPyKeybindings] = None,
show_cursor: bool = True,
cycle: bool = True,
wrap_lines: bool = True,
raise_keyboard_interrupt: bool = True,
mandatory: bool = True,
mandatory_message: str = "Mandatory prompt",
session_result: InquirerPySessionResult = None,
session_result: Optional[InquirerPySessionResult] = None,
) -> None:
if expand_help is None:
expand_help = ExpandHelp(message=help_msg)
Expand Down Expand Up @@ -437,7 +437,7 @@ def _get_prompt_message(self) -> List[Tuple[str, str]]:
)
return display_message

def _handle_toggle_all(self, _, value: bool = None) -> None:
def _handle_toggle_all(self, _, value: Optional[bool] = None) -> None:
"""Override this method to ignore `ExpandHelp`.
:param value: Specify a value to toggle.
Expand Down
18 changes: 9 additions & 9 deletions InquirerPy/prompts/filepath.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Module contains the class to create filepath prompt and filepath completer class."""
import os
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Generator
from typing import TYPE_CHECKING, Any, Callable, Generator, Optional

from prompt_toolkit.completion import Completer, Completion
from prompt_toolkit.completion.base import ThreadedCompleter
Expand Down Expand Up @@ -139,28 +139,28 @@ class FilePathPrompt(InputPrompt):
def __init__(
self,
message: InquirerPyMessage,
style: InquirerPyStyle = None,
style: Optional[InquirerPyStyle] = None,
vi_mode: bool = False,
default: InquirerPyDefault = "",
qmark: str = "?",
amark: str = "?",
instruction: str = "",
long_instruction: str = "",
multicolumn_complete: bool = False,
validate: InquirerPyValidate = None,
validate: Optional[InquirerPyValidate] = None,
invalid_message: str = "Invalid input",
only_directories: bool = False,
only_files: bool = False,
transformer: Callable[[str], Any] = None,
filter: Callable[[str], Any] = None,
keybindings: InquirerPyKeybindings = None,
transformer: Optional[Callable[[str], Any]] = None,
filter: Optional[Callable[[str], Any]] = None,
keybindings: Optional[InquirerPyKeybindings] = None,
wrap_lines: bool = True,
raise_keyboard_interrupt: bool = True,
mandatory: bool = True,
mandatory_message: str = "Mandatory prompt",
session_result: InquirerPySessionResult = None,
input: "Input" = None,
output: "Output" = None,
session_result: Optional[InquirerPySessionResult] = None,
input: Optional["Input"] = None,
output: Optional["Output"] = None,
) -> None:
super().__init__(
message=message,
Expand Down
Loading

0 comments on commit 6915996

Please sign in to comment.