Skip to content

Commit bb3693a

Browse files
Added more type annotations.
1 parent 3ae71dd commit bb3693a

File tree

13 files changed

+69
-21
lines changed

13 files changed

+69
-21
lines changed

prompt_toolkit/contrib/regular_languages/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def get_tuples() -> Iterable[Tuple[str, Tuple[int, int]]]:
422422
for r, re_match in self._re_matches:
423423
for group_name, group_index in r.groupindex.items():
424424
if group_name != _INVALID_TRAILING_INPUT:
425-
regs = cast(Tuple[Tuple[int, int], ...], re_match.regs)
425+
regs = re_match.regs
426426
reg = regs[group_index]
427427
node = self._group_names_to_nodes[group_name]
428428
yield (node, reg)

prompt_toolkit/contrib/ssh/server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ async def _interact(self) -> None:
9797
self._chan.close()
9898
self._input.close()
9999

100-
def terminal_size_changed(self, width, height, pixwidth, pixheight):
100+
def terminal_size_changed(
101+
self, width: int, height: int, pixwidth, pixheight
102+
) -> None:
101103
# Send resize event to the current application.
102104
if self.app_session and self.app_session.app:
103105
self.app_session.app._on_resize()
@@ -144,7 +146,7 @@ def __init__(
144146
) -> None:
145147
self.interact = interact
146148

147-
def begin_auth(self, username):
149+
def begin_auth(self, username: str) -> bool:
148150
# No authentication.
149151
return False
150152

prompt_toolkit/filters/__init__.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,49 @@
2020
from .base import Always, Condition, Filter, FilterOrBool, Never
2121
from .cli import *
2222
from .utils import is_true, to_filter
23+
24+
__all__ = [
25+
# app
26+
"has_arg",
27+
"has_completions",
28+
"completion_is_selected",
29+
"has_focus",
30+
"buffer_has_focus",
31+
"has_selection",
32+
"has_validation_error",
33+
"is_done",
34+
"is_read_only",
35+
"is_multiline",
36+
"renderer_height_is_known",
37+
"in_editing_mode",
38+
"in_paste_mode",
39+
"vi_mode",
40+
"vi_navigation_mode",
41+
"vi_insert_mode",
42+
"vi_insert_multiple_mode",
43+
"vi_replace_mode",
44+
"vi_selection_mode",
45+
"vi_waiting_for_text_object_mode",
46+
"vi_digraph_mode",
47+
"vi_recording_macro",
48+
"emacs_mode",
49+
"emacs_insert_mode",
50+
"emacs_selection_mode",
51+
"shift_selection_mode",
52+
"is_searching",
53+
"control_is_searchable",
54+
"vi_search_direction_reversed",
55+
# base.
56+
"Filter",
57+
"Never",
58+
"Always",
59+
"Condition",
60+
"FilterOrBool",
61+
# utils.
62+
"is_true",
63+
"to_filter",
64+
]
65+
66+
from .cli import __all__ as cli_all
67+
68+
__all__.extend(cli_all)

prompt_toolkit/filters/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def __init__(self, filters: Iterable[Filter]) -> None:
118118

119119
for f in filters:
120120
if isinstance(f, _AndList): # Turn nested _AndLists into one.
121-
self.filters.extend(cast(_AndList, f).filters)
121+
self.filters.extend(f.filters)
122122
else:
123123
self.filters.append(f)
124124

@@ -139,7 +139,7 @@ def __init__(self, filters: Iterable[Filter]) -> None:
139139

140140
for f in filters:
141141
if isinstance(f, _OrList): # Turn nested _OrLists into one.
142-
self.filters.extend(cast(_OrList, f).filters)
142+
self.filters.extend(f.filters)
143143
else:
144144
self.filters.append(f)
145145

@@ -203,7 +203,7 @@ def feature_is_active(): # `feature_is_active` becomes a Filter.
203203
:param func: Callable which takes no inputs and returns a boolean.
204204
"""
205205

206-
def __init__(self, func: Callable[[], bool]):
206+
def __init__(self, func: Callable[[], bool]) -> None:
207207
self.func = func
208208

209209
def __call__(self) -> bool:

prompt_toolkit/formatted_text/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def to_formatted_text(
7171
elif isinstance(value, str):
7272
result = [("", value)]
7373
elif isinstance(value, list):
74-
result = cast(StyleAndTextTuples, value)
74+
result = value # StyleAndTextTuples
7575
elif hasattr(value, "__pt_formatted_text__"):
7676
result = cast("MagicFormattedText", value).__pt_formatted_text__()
7777
elif callable(value):
@@ -146,7 +146,7 @@ def __init__(self, text: str) -> None:
146146
self.text = text
147147

148148
def format(self, *values: AnyFormattedText) -> AnyFormattedText:
149-
def get_result():
149+
def get_result() -> AnyFormattedText:
150150
# Split the template in parts.
151151
parts = self.text.split("{}")
152152
assert len(parts) - 1 == len(values)
@@ -166,7 +166,7 @@ def merge_formatted_text(items: Iterable[AnyFormattedText]) -> AnyFormattedText:
166166
Merge (Concatenate) several pieces of formatted text together.
167167
"""
168168

169-
def _merge_formatted_text():
169+
def _merge_formatted_text() -> AnyFormattedText:
170170
result = FormattedText()
171171
for i in items:
172172
result.extend(to_formatted_text(i))

prompt_toolkit/input/win32_pipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self) -> None:
5353
def closed(self) -> bool:
5454
return self._closed
5555

56-
def fileno(self):
56+
def fileno(self) -> int:
5757
"""
5858
The windows pipe doesn't depend on the file handle.
5959
"""

prompt_toolkit/key_binding/bindings/vi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def load_vi_bindings() -> KeyBindingsBase:
399399
(
400400
("g", "?"),
401401
Always(),
402-
lambda string: cast(str, codecs.encode(string, "rot_13")),
402+
lambda string: codecs.encode(string, "rot_13"),
403403
),
404404
# To lowercase
405405
(("g", "u"), Always(), lambda string: string.lower()),
@@ -1964,7 +1964,7 @@ def _delete_before_multiple_cursors(event: E) -> None:
19641964
event.app.output.bell()
19651965

19661966
@handle("delete", filter=vi_insert_multiple_mode)
1967-
def _delete_after_multiple_cursors(event):
1967+
def _delete_after_multiple_cursors(event: E) -> None:
19681968
"""
19691969
Delete, using multiple cursors.
19701970
"""

prompt_toolkit/layout/containers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ class FloatContainer(Container):
751751
floats=[
752752
Float(xcursor=True,
753753
ycursor=True,
754-
layout=CompletionMenu(...))
754+
content=CompletionMenu(...))
755755
])
756756
757757
:param z_index: (int or None) When specified, this can be used to bring
@@ -1067,7 +1067,7 @@ def __init__(
10671067
allow_cover_cursor: bool = False,
10681068
z_index: int = 1,
10691069
transparent: bool = False,
1070-
):
1070+
) -> None:
10711071

10721072
assert z_index >= 1
10731073

@@ -2700,7 +2700,7 @@ def to_container(container: AnyContainer) -> Container:
27002700
if isinstance(container, Container):
27012701
return container
27022702
elif hasattr(container, "__pt_container__"):
2703-
return to_container(cast("MagicContainer", container).__pt_container__())
2703+
return to_container(container.__pt_container__())
27042704
else:
27052705
raise ValueError("Not a container object: %r" % (container,))
27062706

prompt_toolkit/layout/layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def current_window(self) -> Window:
217217
return self._stack[-1]
218218

219219
@current_window.setter
220-
def current_window(self, value: Window):
220+
def current_window(self, value: Window) -> None:
221221
" Set the :class:`.Window` object to be currently focused. "
222222
self._stack.append(value)
223223

prompt_toolkit/layout/processors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ def filter_processor(item: Processor) -> Optional[Processor]:
849849
include_default_input_processors=False,
850850
lexer=main_control.lexer,
851851
preview_search=True,
852-
search_buffer_control=cast(SearchBufferControl, ti.buffer_control),
852+
search_buffer_control=ti.buffer_control,
853853
)
854854

855855
return buffer_control.create_content(ti.width, ti.height, preview_search=True)

0 commit comments

Comments
 (0)