Skip to content

Commit d860022

Browse files
Various typing fixes:
- Accept `AnyFormattedText` in `create_confirm_session`. - Fixed incorrect import (in TYPE_CHECKING block). - Removed type:ignore comments and casts that are no longer needed.
1 parent d997aab commit d860022

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/prompt_toolkit/contrib/telnet/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _run_in_terminal(self, func: Callable[[], None]) -> None:
244244
# Make sure that when an application was active for this connection,
245245
# that we print the text above the application.
246246
if self.context:
247-
self.context.run(run_in_terminal, func) # type: ignore
247+
self.context.run(run_in_terminal, func)
248248
else:
249249
raise RuntimeError("Called _run_in_terminal outside `run_application`.")
250250

src/prompt_toolkit/document.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ class _ImmutableLineList(List[str]):
5454
def _error(self, *a: object, **kw: object) -> NoReturn:
5555
raise NotImplementedError("Attempt to modify an immutable list.")
5656

57-
__setitem__ = _error # type: ignore
57+
__setitem__ = _error
5858
append = _error
5959
clear = _error
6060
extend = _error
6161
insert = _error
6262
pop = _error
6363
remove = _error
6464
reverse = _error
65-
sort = _error # type: ignore
65+
sort = _error
6666

6767

6868
class _DocumentCache:

src/prompt_toolkit/filters/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from __future__ import annotations
66

7-
from typing import TYPE_CHECKING, cast
7+
from typing import TYPE_CHECKING
88

99
from prompt_toolkit.application.current import get_app
1010
from prompt_toolkit.cache import memoized
@@ -61,7 +61,7 @@ def has_focus(value: FocusableElement) -> Condition:
6161
"""
6262
from prompt_toolkit.buffer import Buffer
6363
from prompt_toolkit.layout import walk
64-
from prompt_toolkit.layout.containers import Container, Window, to_container
64+
from prompt_toolkit.layout.containers import Window, to_container
6565
from prompt_toolkit.layout.controls import UIControl
6666

6767
if isinstance(value, str):
@@ -94,7 +94,7 @@ def test() -> bool:
9494
# focused.
9595
current_window = get_app().layout.current_window
9696

97-
for c in walk(cast(Container, value)):
97+
for c in walk(value):
9898
if isinstance(c, Window) and c == current_window:
9999
return True
100100
return False

src/prompt_toolkit/key_binding/vi_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from prompt_toolkit.clipboard import ClipboardData
77

88
if TYPE_CHECKING:
9-
from .key_bindings.vi import TextObject
9+
from .bindings.vi import TextObject
1010
from .key_processor import KeyPressEvent
1111

1212
__all__ = [

src/prompt_toolkit/shortcuts/prompt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ def prompt(
14741474

14751475

14761476
def create_confirm_session(
1477-
message: str, suffix: str = " (y/n) "
1477+
message: AnyFormattedText, suffix: str = " (y/n) "
14781478
) -> PromptSession[bool]:
14791479
"""
14801480
Create a `PromptSession` object for the 'confirm' function.
@@ -1505,7 +1505,7 @@ def _(event: E) -> None:
15051505
return session
15061506

15071507

1508-
def confirm(message: str = "Confirm?", suffix: str = " (y/n) ") -> bool:
1508+
def confirm(message: AnyFormattedText = "Confirm?", suffix: str = " (y/n) ") -> bool:
15091509
"""
15101510
Display a confirmation prompt that returns True/False.
15111511
"""

0 commit comments

Comments
 (0)