Skip to content

Commit d0da43e

Browse files
Fixed typing issues in tempfile/tempfile_suffix.
1 parent 1e4e7be commit d0da43e

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

prompt_toolkit/buffer.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from .history import History, InMemoryHistory
4444
from .search import SearchDirection, SearchState
4545
from .selection import PasteMode, SelectionState, SelectionType
46-
from .utils import Event, call_if_callable
46+
from .utils import Event, to_str
4747
from .validation import ValidationError, Validator
4848

4949
__all__ = [
@@ -1401,8 +1401,7 @@ def _editor_simple_tempfile(self) -> Tuple[str, Callable[[], None]]:
14011401
Simple (file) tempfile implementation.
14021402
Return (tempfile, cleanup_func).
14031403
"""
1404-
suffix = call_if_callable(self.tempfile_suffix)
1405-
suffix = str(suffix) if suffix else None
1404+
suffix = to_str(self.tempfile_suffix)
14061405
descriptor, filename = tempfile.mkstemp(suffix)
14071406

14081407
os.write(descriptor, self.text.encode('utf-8'))
@@ -1415,7 +1414,7 @@ def cleanup() -> None:
14151414

14161415
def _editor_complex_tempfile(self) -> Tuple[str, Callable[[], None]]:
14171416
# Complex (directory) tempfile implementation.
1418-
headtail = call_if_callable(self.tempfile)
1417+
headtail = to_str(self.tempfile)
14191418
if not headtail:
14201419
# Revert to simple case.
14211420
return self._editor_simple_tempfile()

prompt_toolkit/shortcuts/prompt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
SwapLightAndDarkStyleTransformation,
130130
merge_style_transformations,
131131
)
132-
from prompt_toolkit.utils import get_cwidth, suspend_to_background_supported
132+
from prompt_toolkit.utils import get_cwidth, suspend_to_background_supported, to_str
133133
from prompt_toolkit.validation import DynamicValidator, Validator
134134
from prompt_toolkit.widgets.toolbars import (
135135
SearchToolbar,
@@ -481,8 +481,8 @@ def accept(buff: Buffer) -> bool:
481481
history=self.history,
482482
auto_suggest=DynamicAutoSuggest(lambda: self.auto_suggest),
483483
accept_handler=accept,
484-
tempfile_suffix=lambda: self.tempfile_suffix,
485-
tempfile=lambda: self.tempfile)
484+
tempfile_suffix=lambda: to_str(self.tempfile_suffix or ''),
485+
tempfile=lambda: to_str(self.tempfile or ''))
486486

487487
def _create_search_buffer(self) -> Buffer:
488488
return Buffer(name=SEARCH_BUFFER)

prompt_toolkit/utils.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
'is_windows',
2727
'in_main_thread',
2828
'take_using_weights',
29-
'call_if_callable',
3029
'to_str',
3130
'to_int',
3231
'to_float',
@@ -262,14 +261,6 @@ def take_using_weights(
262261
i += 1
263262

264263

265-
def call_if_callable(value: Union[Callable[[], _T], _T]) -> _T:
266-
" Call if callable, otherwise return as is.. "
267-
if callable(value):
268-
return call_if_callable(value())
269-
else:
270-
return value
271-
272-
273264
def to_str(value: Union[Callable[[], str], str]) -> str:
274265
" Turn callable or string into string. "
275266
if callable(value):

0 commit comments

Comments
 (0)