Skip to content

Commit 30c576d

Browse files
committed
Make mypy happy
1 parent fe605cf commit 30c576d

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

Lib/_pyrepl/_module_completer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self, namespace: Mapping[str, Any] | None = None) -> None:
7272
self._curr_sys_path: list[str] = sys.path[:]
7373
self._stdlib_path = os.path.dirname(importlib.__path__[0])
7474

75-
def get_completions(self, line: str) -> tuple[list[str], list[object], CompletionAction | None] | None:
75+
def get_completions(self, line: str) -> tuple[list[str], list[Any], CompletionAction | None] | None:
7676
"""Return the next possible import completions for 'line'.
7777
7878
For attributes completion, if the module to complete from is not
@@ -89,7 +89,7 @@ def get_completions(self, line: str) -> tuple[list[str], list[object], Completio
8989
# no completions are available
9090
return [], [], None
9191

92-
def complete(self, from_name: str | None, name: str | None) -> tuple[list[str], list[object], CompletionAction | None]:
92+
def complete(self, from_name: str | None, name: str | None) -> tuple[list[str], list[Any], CompletionAction | None]:
9393
if from_name is None:
9494
# import x.y.z<tab>
9595
assert name is not None
@@ -180,7 +180,7 @@ def _is_stdlib_module(self, module_info: pkgutil.ModuleInfo) -> bool:
180180
return (isinstance(module_info.module_finder, FileFinder)
181181
and module_info.module_finder.path == self._stdlib_path)
182182

183-
def find_attributes(self, path: str, prefix: str) -> tuple[list[str], list[object], CompletionAction | None]:
183+
def find_attributes(self, path: str, prefix: str) -> tuple[list[str], list[Any], CompletionAction | None]:
184184
"""Find all attributes of module 'path' that start with 'prefix'."""
185185
attributes, values, action = self._find_attributes(path, prefix)
186186
# Filter out invalid attribute names
@@ -193,7 +193,7 @@ def find_attributes(self, path: str, prefix: str) -> tuple[list[str], list[objec
193193
filtered_values.append(val)
194194
return filtered_names, filtered_values, action
195195

196-
def _find_attributes(self, path: str, prefix: str) -> tuple[list[str], list[object], CompletionAction | None]:
196+
def _find_attributes(self, path: str, prefix: str) -> tuple[list[str], list[Any], CompletionAction | None]:
197197
path = self._resolve_relative_path(path) # type: ignore[assignment]
198198
if path is None:
199199
return [], [], None

Lib/_pyrepl/fancycompleter.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
import keyword
99
import types
1010

11+
TYPE_CHECKING = False
12+
13+
if TYPE_CHECKING:
14+
from typing import Any
15+
from _colorize import Theme
16+
1117

1218
def safe_getattr(obj, name):
1319
# Mirror rlcompleter's safeguards so completion does not
@@ -21,13 +27,13 @@ def safe_getattr(obj, name):
2127
return getattr(obj, name, None)
2228

2329

24-
def colorize_matches(names, values, theme):
30+
def colorize_matches(names: list[str], values: list[Any], theme: Theme) -> list[str]:
2531
return [
2632
_color_for_obj(name, obj, theme)
2733
for name, obj in zip(names, values)
2834
]
2935

30-
def _color_for_obj(name, value, theme):
36+
def _color_for_obj(name: str, value: Any, theme: Theme) -> str:
3137
t = type(value)
3238
color = _color_by_type(t, theme)
3339
return f"{color}{name}{ANSIColors.RESET}"

Lib/_pyrepl/readline.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class ReadlineConfig:
104104
readline_completer: Completer | None = None
105105
completer_delims: frozenset[str] = frozenset(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?")
106106
module_completer: ModuleCompleter = field(default_factory=make_default_module_completer)
107-
colorize_completions: Callable[[list[str], list[object]], list[str]] | None = None
107+
colorize_completions: Callable[[list[str], list[Any]], list[str]] | None = None
108108

109109
@dataclass(kw_only=True)
110110
class ReadlineAlikeReader(historical_reader.HistoricalReader, CompletingReader):
@@ -623,9 +623,10 @@ def _setup(namespace: Mapping[str, Any]) -> None:
623623
completer_cls = RLCompleter if use_basic_completer else FancyCompleter
624624
completer = completer_cls(namespace)
625625
_wrapper.config.readline_completer = completer.complete
626-
if getattr(completer, 'use_colors', False):
626+
if isinstance(completer, FancyCompleter) and completer.use_colors:
627+
theme = completer.theme
627628
def _colorize(names: list[str], values: list[object]) -> list[str]:
628-
return colorize_matches(names, values, completer.theme)
629+
return colorize_matches(names, values, theme)
629630
_wrapper.config.colorize_completions = _colorize
630631
_wrapper.config.module_completer = ModuleCompleter(namespace)
631632

0 commit comments

Comments
 (0)