Skip to content

Commit

Permalink
modified: src/click_repl/_globals.py
Browse files Browse the repository at this point in the history
	modified:   src/click_repl/_repl.py
	modified:   src/click_repl/bottom_bar.py
	modified:   src/click_repl/completer.py
	modified:   src/click_repl/core.py
	modified:   src/click_repl/parser.py
	modified:   src/click_repl/utils.py
  • Loading branch information
GhostOps77 committed Mar 18, 2024
1 parent d963901 commit 3517c62
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 39 deletions.
3 changes: 1 addition & 2 deletions src/click_repl/_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import sys
import typing as t
from threading import local
from typing import List
from typing import NoReturn

import click
Expand Down Expand Up @@ -172,7 +171,7 @@

# To store the ReplContext objects generated throughout the Runtime.
_locals = local()
ctx_stack: List[ReplContext] = []
ctx_stack: list[ReplContext] = []
_locals.ctx_stack = ctx_stack
# ctx_stack = _locals.ctx_stack

Expand Down
25 changes: 12 additions & 13 deletions src/click_repl/_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import sys
import traceback
from typing import Any
from typing import Dict
from typing import Sequence
from typing import cast

Expand Down Expand Up @@ -81,11 +80,11 @@ class Repl:
def __init__(
self,
ctx: Context,
prompt_kwargs: Dict[str, Any] = {},
prompt_kwargs: dict[str, Any] = {},
completer_cls: type[Completer] | None = ClickCompleter,
validator_cls: type[Validator] | None = ClickValidator,
completer_kwargs: Dict[str, Any] = {},
validator_kwargs: Dict[str, Any] = {},
completer_kwargs: dict[str, Any] = {},
validator_kwargs: dict[str, Any] = {},
internal_command_prefix: str | None = ":",
system_command_prefix: str | None = "!",
) -> None:
Expand Down Expand Up @@ -144,8 +143,8 @@ def get_command() -> str:
self.get_command = get_command

def _bootstrap_completer_kwargs(
self, completer_cls: type[Completer] | None, completer_kwargs: Dict[str, Any]
) -> Dict[str, Any]:
self, completer_cls: type[Completer] | None, completer_kwargs: dict[str, Any]
) -> dict[str, Any]:
"""
Generates bootstrap keyword arguments for initializing a
`prompt_toolkit.completer.Completer` object, either using
Expand Down Expand Up @@ -180,8 +179,8 @@ def _bootstrap_completer_kwargs(
return default_completer_kwargs

def _bootstrap_validator_kwargs(
self, validator_cls: type[Validator] | None, validator_kwargs: Dict[str, Any]
) -> Dict[str, Any]:
self, validator_cls: type[Validator] | None, validator_kwargs: dict[str, Any]
) -> dict[str, Any]:
"""
Generates bootstrap keyword arguments for initializing a
`prompt_toolkit.validation.Validator` object, either
Expand Down Expand Up @@ -222,11 +221,11 @@ def _bootstrap_validator_kwargs(
def _bootstrap_prompt_kwargs(
self,
completer_cls: type[Completer] | None,
completer_kwargs: Dict[str, Any],
completer_kwargs: dict[str, Any],
validator_cls: type[Validator] | None,
validator_kwargs: Dict[str, Any],
prompt_kwargs: Dict[str, Any],
) -> Dict[str, Any]:
validator_kwargs: dict[str, Any],
prompt_kwargs: dict[str, Any],
) -> dict[str, Any]:
if not ISATTY:
return {}

Expand Down Expand Up @@ -373,7 +372,7 @@ def loop(self) -> None:

def repl(
group_ctx: Context,
prompt_kwargs: Dict[str, Any] = {},
prompt_kwargs: dict[str, Any] = {},
cls: type[Repl] = Repl,
**attrs: Any,
) -> None:
Expand Down
5 changes: 2 additions & 3 deletions src/click_repl/bottom_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from __future__ import annotations

import typing as t
from typing import List
from typing import Tuple

import click
Expand Down Expand Up @@ -35,7 +34,7 @@


class ParamInfo(TypedDict):
name: Tuple[str, str]
name: tuple[str, str]
type_info: StyleAndTextTuples
nargs_info: StyleAndTextTuples

Expand Down Expand Up @@ -306,7 +305,7 @@ def get_param_nargs_info(
assert self.state is not None, "state cannot be None"

# Calculate the number of non-None values received for the parameter.
param_values: List[str] = (
param_values: list[str] = (
self.state.current_ctx.params[param.name] or [] # type:ignore[index]
)

Expand Down
2 changes: 1 addition & 1 deletion src/click_repl/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def get_completion_for_boolean_type(

_incomplete = incomplete.expand_envvars()

boolean_mapping: Dict[str, Tuple[str, ...]] = {
boolean_mapping: dict[str, Tuple[str, ...]] = {
"true": ("1", "true", "t", "yes", "y", "on"),
"false": ("0", "false", "f", "no", "n", "off"),
}
Expand Down
11 changes: 5 additions & 6 deletions src/click_repl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import Any
from typing import Callable
from typing import Dict
from typing import List

import click
from click import Context
Expand All @@ -32,11 +31,11 @@

class InfoDict(TypedDict):
group_ctx: Context
prompt_kwargs: Dict[str, Any]
prompt_kwargs: dict[str, Any]
session: _PromptSession | None
internal_command_system: InternalCommandSystem
parent: ReplContext | None
_history: List[str]
_history: list[str]
current_state: ReplParsingState | None
bottombar: BottomBar | None

Expand Down Expand Up @@ -93,7 +92,7 @@ def __init__(
group_ctx: Context,
internal_command_system: InternalCommandSystem,
bottombar: BottomBar | None = None,
prompt_kwargs: Dict[str, Any] = {},
prompt_kwargs: dict[str, Any] = {},
parent: ReplContext | None = None,
) -> None:
session: _PromptSession | None
Expand All @@ -109,7 +108,7 @@ def __init__(
self.session = session
self.bottombar = bottombar

self._history: List[str] = []
self._history: list[str] = []
self.internal_command_system = internal_command_system
self.group_ctx: Final[Context] = group_ctx
self.prompt_kwargs = prompt_kwargs
Expand Down Expand Up @@ -231,7 +230,7 @@ def __init__(
prompt: str = "> ",
startup: Callable[[], None] | None = None,
cleanup: Callable[[], None] | None = None,
repl_kwargs: Dict[str, Any] = {},
repl_kwargs: dict[str, Any] = {},
**attrs: Any,
) -> None:
attrs["invoke_without_command"] = True
Expand Down
10 changes: 5 additions & 5 deletions src/click_repl/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def split_arg_string(string: str, posix: bool = True) -> List[str]:
lex = shlex(string, posix=posix, punctuation_chars=True)
lex.whitespace_split = True
lex.escape = ""
out: List[str] = []
out: list[str] = []

try:
out.extend(lex)
Expand Down Expand Up @@ -186,15 +186,15 @@ def __init__(
self,
cli_ctx: Context,
current_ctx: Context,
args: Tuple[str, ...],
args: tuple[str, ...],
) -> None:
self.cli_ctx = cli_ctx
self.cli = t.cast(MultiCommand, self.cli_ctx.command)

self.current_ctx = current_ctx
self.args = args

self.remaining_params: List[Parameter] = []
self.remaining_params: list[Parameter] = []
self.double_dash_found = getattr(current_ctx, "_double_dash_found", False)

self.current_group, self.current_command, self.current_param = self.parse()
Expand All @@ -218,7 +218,7 @@ def __repr__(self) -> str:
return f'"{str(self)}"'

def __key(self) -> _KEY:
keys: List[InfoDict | None] = []
keys: list[InfoDict | None] = []

for i in (
self.current_group,
Expand Down Expand Up @@ -364,7 +364,7 @@ def parse_param_arg(self, current_command: Command) -> click.Argument | None:
def _resolve_repl_parsing_state(
cli_ctx: Context,
current_ctx: Context,
args: Tuple[str, ...],
args: tuple[str, ...],
) -> ReplParsingState:
return ReplParsingState(cli_ctx, current_ctx, args)

Expand Down
16 changes: 7 additions & 9 deletions src/click_repl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
from collections.abc import Iterator
from functools import lru_cache
from typing import Any
from typing import Dict
from typing import Iterable
from typing import List
from typing import Tuple

import click
Expand All @@ -38,7 +36,7 @@


def append_classname_to_all_tokens(
tokens_list: StyleAndTextTuples, classes: List[str] = []
tokens_list: StyleAndTextTuples, classes: list[str] = []
) -> StyleAndTextTuples:
if not classes:
return tokens_list
Expand Down Expand Up @@ -126,12 +124,12 @@ def is_param_value_incomplete(
)


def get_option_flag_sep(options: List[str]) -> str:
def get_option_flag_sep(options: list[str]) -> str:
any_prefix_is_slash = any(split_opt(opt)[0] == "/" for opt in options)
return ";" if any_prefix_is_slash else "/"


def join_options(options: List[str]) -> Tuple[List[str], str]:
def join_options(options: list[str]) -> Tuple[list[str], str]:
# Same implementation as click.formatting.join_options function, but much simpler.
return sorted(options, key=len), get_option_flag_sep(options)

Expand Down Expand Up @@ -279,10 +277,10 @@ def get_info_dict(
def _generate_next_click_ctx(
multicommand: MultiCommand,
parent_ctx: Context,
args: Tuple[str, ...],
args: tuple[str, ...],
proxy: bool = False,
**ctx_kwargs: Dict[str, Any],
) -> Tuple[Context, Command | None]:
**ctx_kwargs: dict[str, Any],
) -> tuple[Context, Command | None]:
if not args:
return parent_ctx, None

Expand Down Expand Up @@ -312,7 +310,7 @@ def _generate_next_click_ctx(


@lru_cache(maxsize=3)
def _resolve_context(ctx: Context, args: Tuple[str, ...], proxy: bool = False) -> Context:
def _resolve_context(ctx: Context, args: tuple[str, ...], proxy: bool = False) -> Context:
while args:
command = ctx.command

Expand Down

0 comments on commit 3517c62

Please sign in to comment.