Skip to content

Commit c1a4310

Browse files
Several typing fixes.
1 parent 3ec97d7 commit c1a4310

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

ptpython/python_input.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,6 @@ def __init__(
347347
"classic": ClassicPrompt(),
348348
}
349349

350-
self.get_input_prompt = lambda: self.all_prompt_styles[
351-
self.prompt_style
352-
].in_prompt()
353-
354-
self.get_output_prompt = lambda: self.all_prompt_styles[
355-
self.prompt_style
356-
].out_prompt()
357-
358350
#: Load styles.
359351
self.code_styles: dict[str, BaseStyle] = get_all_code_styles()
360352
self.ui_styles = get_all_ui_styles()
@@ -425,6 +417,12 @@ def __init__(
425417
else:
426418
self._app = None
427419

420+
def get_input_prompt(self) -> AnyFormattedText:
421+
return self.all_prompt_styles[self.prompt_style].in_prompt()
422+
423+
def get_output_prompt(self) -> AnyFormattedText:
424+
return self.all_prompt_styles[self.prompt_style].out_prompt()
425+
428426
def _accept_handler(self, buff: Buffer) -> bool:
429427
app = get_app()
430428
app.exit(result=buff.text)

ptpython/repl.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
import types
2020
import warnings
2121
from dis import COMPILER_FLAG_NAMES
22-
from typing import Any, Callable, ContextManager, Iterable
22+
from pathlib import Path
23+
from typing import Any, Callable, ContextManager, Iterable, Sequence
2324

2425
from prompt_toolkit.formatted_text import OneStyleAndTextTuple
2526
from prompt_toolkit.patch_stdout import patch_stdout as patch_stdout_context
@@ -64,7 +65,7 @@ def _has_coroutine_flag(code: types.CodeType) -> bool:
6465

6566
class PythonRepl(PythonInput):
6667
def __init__(self, *a, **kw) -> None:
67-
self._startup_paths = kw.pop("startup_paths", None)
68+
self._startup_paths: Sequence[str | Path] | None = kw.pop("startup_paths", None)
6869
super().__init__(*a, **kw)
6970
self._load_start_paths()
7071

@@ -348,7 +349,7 @@ def _store_eval_result(self, result: object) -> None:
348349
def get_compiler_flags(self) -> int:
349350
return super().get_compiler_flags() | PyCF_ALLOW_TOP_LEVEL_AWAIT
350351

351-
def _compile_with_flags(self, code: str, mode: str):
352+
def _compile_with_flags(self, code: str, mode: str) -> Any:
352353
"Compile code with the right compiler flags."
353354
return compile(
354355
code,
@@ -459,13 +460,13 @@ def enter_to_continue() -> None:
459460

460461

461462
def embed(
462-
globals=None,
463-
locals=None,
463+
globals: dict[str, Any] | None = None,
464+
locals: dict[str, Any] | None = None,
464465
configure: Callable[[PythonRepl], None] | None = None,
465466
vi_mode: bool = False,
466467
history_filename: str | None = None,
467468
title: str | None = None,
468-
startup_paths=None,
469+
startup_paths: Sequence[str | Path] | None = None,
469470
patch_stdout: bool = False,
470471
return_asyncio_coroutine: bool = False,
471472
) -> None:
@@ -494,10 +495,10 @@ def embed(
494495

495496
locals = locals or globals
496497

497-
def get_globals():
498+
def get_globals() -> dict[str, Any]:
498499
return globals
499500

500-
def get_locals():
501+
def get_locals() -> dict[str, Any]:
501502
return locals
502503

503504
# Create REPL.

0 commit comments

Comments
 (0)