Skip to content

Commit cdbaef7

Browse files
Various mypy related fixes.
1 parent f045ff9 commit cdbaef7

File tree

7 files changed

+25
-11
lines changed

7 files changed

+25
-11
lines changed

mypy.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ strict_optional = True
1515
warn_redundant_casts = True
1616
warn_return_any = True
1717
warn_unused_configs = True
18-
warn_unused_ignores = True
18+
19+
# We have a 'type:ignore' that's not needed on Python 3.6.
20+
warn_unused_ignores = False

src/prompt_toolkit/application/application.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Any,
2323
Awaitable,
2424
Callable,
25+
Coroutine,
2526
Dict,
2627
FrozenSet,
2728
Generator,
@@ -1017,7 +1018,7 @@ def trace_dispatch(
10171018
CustomPdb(stdout=sys.__stdout__).set_trace(frame)
10181019

10191020
def create_background_task(
1020-
self, coroutine: Awaitable[None]
1021+
self, coroutine: Coroutine[Any, Any, None]
10211022
) -> "asyncio.Task[None]":
10221023
"""
10231024
Start a background task (coroutine) for the running application. When
@@ -1029,7 +1030,7 @@ def create_background_task(
10291030
10301031
Not threadsafe.
10311032
"""
1032-
task = get_event_loop().create_task(coroutine)
1033+
task: asyncio.Task[None] = get_event_loop().create_task(coroutine)
10331034
self.background_tasks.append(task)
10341035
return task
10351036

src/prompt_toolkit/buffer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Any,
1818
Awaitable,
1919
Callable,
20+
Coroutine,
2021
Deque,
2122
Iterable,
2223
List,
@@ -1692,7 +1693,7 @@ def start_completion(
16921693
)
16931694
)
16941695

1695-
def _create_completer_coroutine(self) -> Callable[..., Awaitable[None]]:
1696+
def _create_completer_coroutine(self) -> Callable[..., Coroutine[Any, Any, None]]:
16961697
"""
16971698
Create function for asynchronous autocompletion.
16981699
@@ -1822,7 +1823,7 @@ def proceed() -> bool:
18221823

18231824
return async_completer
18241825

1825-
def _create_auto_suggest_coroutine(self) -> Callable[[], Awaitable[None]]:
1826+
def _create_auto_suggest_coroutine(self) -> Callable[[], Coroutine[Any, Any, None]]:
18261827
"""
18271828
Create function for asynchronous auto suggestion.
18281829
(This can be in another thread.)
@@ -1849,7 +1850,9 @@ async def async_suggestor() -> None:
18491850

18501851
return async_suggestor
18511852

1852-
def _create_auto_validate_coroutine(self) -> Callable[[], Awaitable[None]]:
1853+
def _create_auto_validate_coroutine(
1854+
self,
1855+
) -> Callable[[], Coroutine[Any, Any, None]]:
18531856
"""
18541857
Create a function for asynchronous validation while typing.
18551858
(This can be in another thread.)

src/prompt_toolkit/contrib/telnet/server.py

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

src/prompt_toolkit/eventloop/dummy_contextvars.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@
44
As long as there is only one application running at a time, we don't need the
55
real contextvars. So, stuff like the telnet-server and so on requires 3.7.
66
"""
7-
from typing import Any, Callable, Generic, Optional, TypeVar
7+
from typing import TYPE_CHECKING, Any, Callable, Generic, Optional, TypeVar
8+
9+
if TYPE_CHECKING:
10+
from typing_extensions import ParamSpec
811

912

1013
def copy_context() -> "Context":
1114
return Context()
1215

1316

17+
if TYPE_CHECKING:
18+
_P = ParamSpec("_P")
1419
_T = TypeVar("_T")
1520

1621

1722
class Context:
18-
def run(self, callable: Callable[..., _T], *args: Any, **kwargs: Any) -> _T:
23+
def run(
24+
self, callable: "Callable[_P, _T]", *args: "_P.args", **kwargs: "_P.kwargs"
25+
) -> _T:
1926
return callable(*args, **kwargs)
2027

2128
def copy(self) -> "Context":

src/prompt_toolkit/layout/menus.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Iterable,
88
List,
99
Optional,
10+
Sequence,
1011
Tuple,
1112
TypeVar,
1213
Union,
@@ -406,7 +407,7 @@ def create_content(self, width: int, height: int) -> UIContent:
406407

407408
def grouper(
408409
n: int, iterable: Iterable[_T], fillvalue: Optional[_T] = None
409-
) -> Iterable[List[_T]]:
410+
) -> Iterable[Sequence[Optional[_T]]]:
410411
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
411412
args = [iter(iterable)] * n
412413
return zip_longest(fillvalue=fillvalue, *args)

src/prompt_toolkit/widgets/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ class Checkbox(CheckboxList[str]):
892892

893893
def __init__(self, text: AnyFormattedText = "", checked: bool = False) -> None:
894894
values = [("value", text)]
895-
CheckboxList.__init__(self, values=values)
895+
super().__init__(values=values)
896896
self.checked = checked
897897

898898
@property

0 commit comments

Comments
 (0)