8000 Added mypy.ini and a few type annotations improvements. · cool-RR/python-prompt-toolkit@ab073d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab073d8

Browse files
Added mypy.ini and a few type annotations improvements.
1 parent 954e166 commit ab073d8

File tree

10 files changed

+28
-18
lines changed

10 files changed

+28
-18
lines changed

mypy.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[mypy]
2+
ignore_missing_imports = True
3+
no_implicit_optional = True
4+
platform = win32
5+
strict_equality = True
6+
strict_optional = True
7+
warn_unused_ignores = True

prompt_toolkit/buffer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ def __init__(self,
220220
accept_handler: Optional[BufferAcceptHandler] = None,
221221
read_only: FilterOrBool = False,
222222
multiline: FilterOrBool = True,
223-
on_text_changed: BufferEventHandler = None,
224-
on_text_insert: BufferEventHandler = None,
225-
on_cursor_position_changed: BufferEventHandler = None,
226-
on_completions_changed: BufferEventHandler = None,
227-
on_suggestion_set: BufferEventHandler = None):
223+
on_text_changed: Optional[BufferEventHandler] = None,
224+
on_text_insert: Optional[BufferEventHandler] = None,
225+
on_cursor_position_changed: Optional[BufferEventHandler] = None,
226+
on_completions_changed: Optional[BufferEventHandler] = None,
227+
on_suggestion_set: Optional[BufferEventHandler] = None):
228228

229229
# Accept both filters and booleans as input.
230230
enable_history_search = to_filter(enable_history_search)

prompt_toolkit/completion/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, text: str, start_position: int = 0,
5555
assert self.start_position <= 0
5656

5757
def __repr__(self) -> str:
58-
if self.display == self.text:
58+
if isinstance(self.display, str) and self.display == self.text:
5959
return '%s(text=%r, start_position=%r)' % (
6060
self.__class__.__name__, self.text, self.start_position)
6161
else:

prompt_toolkit/eventloop/dummy_contextvars.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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, TypeVar
7+
from typing import Any, Callable, Generic, Optional, TypeVar
88

99

1010
def copy_context() -> 'Context':
@@ -24,15 +24,15 @@ class Token(Generic[_T]):
2424

2525

2626
class ContextVar(Generic[_T]):
27-
def __init__(self, name: str, *, default: _T = None) -> None:
27+
def __init__(self, name: str, *, default: Optional[_T] = None) -> None:
2828
self._name = name
2929
self._value = default
3030

3131
@property
3232
def name(self) -> str:
3333
return self._name
3434

35-
def get(self, default: _T = None) -> _T:
35+
def get(self, default: Optional[_T] = None) -> _T:
3636
result = self._value or default
3737
if result is None:
3838
raise LookupError

prompt_toolkit/formatted_text/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def __pt_formatted_text__(self) -> StyleAndTextTuples:
5050
'MagicFormattedText',
5151
StyleAndTextTuples,
5252
# Callable[[], 'AnyFormattedText'] # Recursive definition not supported by mypy.
53-
Callable[[], Any]
53+
Callable[[], Any],
54+
None
5455
]
5556

5657

prompt_toolkit/input/win32.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from contextlib import contextmanager
77
from ctypes import pointer, windll
88
from ctypes.wintypes import DWORD
9-
from typing import Callable, ContextManager, Dict, Iterable
9+
from typing import Callable, ContextManager, Dict, Iterable, Optional
1010

1111
from prompt_toolkit.eventloop import run_in_executor_with_context
1212
from prompt_toolkit.eventloop.win32 import wait_for_handles
@@ -239,6 +239,8 @@ def read(self) -> Iterable[KeyPress]:
239239

240240
if self.recognize_paste and self._is_paste(all_keys):
241241
gen = iter(all_keys)
242+
k: Optional[KeyPress]
243+
242244
for k in gen:
243245
# Pasting: if the current key consists of text or \n, turn it
244246
# into a BracketedPaste.

prompt_toolkit/key_binding/bindings/completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def display_completions_like_readline(event: E) -> None:
8080

8181

8282
def _display_completions_like_readline(
83-
app: 'Application', completions: List[Completion]) -> Future:
83+
app: 'Application', completions: List[Completion]) -> 'Future[None]':
8484
"""
8585
Display the list of completions in columns above the prompt.
8686
This will ask for a confirmation if there are too many completions to fit

prompt_toolkit/key_binding/key_processor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(self, key_bindings: KeyBindingsBase) -> None:
9898

9999
def reset(self) -> None:
100100
self._previous_key_sequence: List[KeyPress] = []
101-
self._previous_handler = None
101+
self._previous_handler: Optional[Binding] = None
102102

103103
# The queue of keys not yet send to our _process generator/state machine.
104104
self.input_queue: Deque[KeyPress] = deque()
@@ -304,7 +304,7 @@ def empty_queue(self) -> List[KeyPress]:
304304
key_presses = [k for k in key_presses if k.key != Keys.CPRResponse]
305305
return key_presses
306306

307-
def _call_handler(self, handler, key_sequence: List[KeyPress]) -> None:
307+
def _call_handler(self, handler: Binding, key_sequence: List[KeyPress]) -> None:
308308
app = get_app()
309309
was_recording_emacs = app.emacs_state.is_recording
310310
was_recording_vi = bool(app.vi_state.recording_register)

prompt_toolkit/layout/containers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class _Split(Container):
190190
def __init__(self, children: Sequence[AnyContainer],
191191
window_too_small: Optional[Container] = None,
192192
padding: AnyDimension = Dimension.exact(0),
193-
padding_char: str = None,
193+
padding_char: Optional[str] = None,
194194
padding_style: str = '',
195195
width: AnyDimension = None,
196196
height: AnyDimension = None,
@@ -267,7 +267,7 @@ def __init__(self,
267267
height: AnyDimension = None,
268268
z_index: Optional[int] = None,
269269
modal: bool = False,
270-
key_bindings: KeyBindingsBase = None,
270+
key_bindings: Optional[KeyBindingsBase] = None,
271271
style: Union[str, Callable[[], str]] = '') -> None:
272272

273273
super().__init__(
@@ -478,7 +478,7 @@ def __init__(self,
478478
height: AnyDimension = None,
479479
z_index: Optional[int] = None,
480480
modal: bool = False,
481-
key_bindings: KeyBindingsBase = None,
481+
key_bindings: Optional[KeyBindingsBase] = None,
482482
style: Union[str, Callable[[], str]] = '') -> None:
483483

484484
super().__init__(

prompt_toolkit/shortcuts/progress_bar/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
try:
6666
import contextvars
6767
except ImportError:
68-
from prompt_toolkit.eventloop import dummy_contextvars as contextvars
68+
from prompt_toolkit.eventloop import dummy_contextvars as contextvars # type: ignore
6969

7070

7171
__all__ = [

0 commit comments

Comments
 (0)
0