Skip to content

Commit fb4949a

Browse files
Typecheck examples.
1 parent 030790f commit fb4949a

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ jobs:
1919
python-version: ${{ matrix.python-version }}
2020
- name: Type Checking
2121
run: |
22-
uvx --with . mypy src/ptpython
22+
uvx --with . mypy src/ptpython/
23+
uvx --with . mypy examples/
2324
- name: Code formatting
2425
if: ${{ matrix.python-version == '3.13' }}
2526
run: |

examples/ssh-and-telnet-embed.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
https://gist.github.com/vxgmichel/7685685b3e5ead04ada4a3ba75a48eef
77
"""
88

9+
from __future__ import annotations
10+
911
import asyncio
1012
import pathlib
1113

@@ -15,7 +17,7 @@
1517
PromptToolkitSSHServer,
1618
PromptToolkitSSHSession,
1719
)
18-
from prompt_toolkit.contrib.telnet.server import TelnetServer
20+
from prompt_toolkit.contrib.telnet.server import TelnetConnection, TelnetServer
1921

2022
from ptpython.repl import embed
2123

@@ -28,7 +30,7 @@ def ensure_key(filename: str = "ssh_host_key") -> str:
2830
return str(path)
2931

3032

31-
async def interact(connection: PromptToolkitSSHSession) -> None:
33+
async def interact(connection: PromptToolkitSSHSession | TelnetConnection) -> None:
3234
global_dict = {**globals(), "print": print_formatted_text}
3335
await embed(return_asyncio_coroutine=True, globals=global_dict)
3436

src/ptpython/repl.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@
2020
import warnings
2121
from dis import COMPILER_FLAG_NAMES
2222
from pathlib import Path
23-
from typing import Any, Callable, ContextManager, Iterable, NoReturn, Sequence
23+
from typing import (
24+
Any,
25+
Callable,
26+
ContextManager,
27+
Coroutine,
28+
Iterable,
29+
Literal,
30+
NoReturn,
31+
Sequence,
32+
overload,
33+
)
2434

2535
from prompt_toolkit.formatted_text import OneStyleAndTextTuple
2636
from prompt_toolkit.patch_stdout import patch_stdout as patch_stdout_context
@@ -505,6 +515,34 @@ class ReplExit(Exception):
505515
"""
506516

507517

518+
@overload
519+
def embed(
520+
globals: dict[str, Any] | None = ...,
521+
locals: dict[str, Any] | None = ...,
522+
configure: Callable[[PythonRepl], None] | None = ...,
523+
vi_mode: bool = ...,
524+
history_filename: str | None = ...,
525+
title: str | None = ...,
526+
startup_paths: Sequence[str | Path] | None = ...,
527+
patch_stdout: bool = ...,
528+
return_asyncio_coroutine: Literal[False] = ...,
529+
) -> None: ...
530+
531+
532+
@overload
533+
def embed(
534+
globals: dict[str, Any] | None = ...,
535+
locals: dict[str, Any] | None = ...,
536+
configure: Callable[[PythonRepl], None] | None = ...,
537+
vi_mode: bool = ...,
538+
history_filename: str | None = ...,
539+
title: str | None = ...,
540+
startup_paths: Sequence[str | Path] | None = ...,
541+
patch_stdout: bool = ...,
542+
return_asyncio_coroutine: Literal[True] = ...,
543+
) -> Coroutine[Any, Any, None]: ...
544+
545+
508546
def embed(
509547
globals: dict[str, Any] | None = None,
510548
locals: dict[str, Any] | None = None,
@@ -515,7 +553,7 @@ def embed(
515553
startup_paths: Sequence[str | Path] | None = None,
516554
patch_stdout: bool = False,
517555
return_asyncio_coroutine: bool = False,
518-
) -> None:
556+
) -> None | Coroutine[Any, Any, None]:
519557
"""
520558
Call this to embed Python shell at the current point in your program.
521559
It's similar to `IPython.embed` and `bpython.embed`. ::
@@ -577,3 +615,4 @@ async def coroutine() -> None:
577615
else:
578616
with patch_context:
579617
repl.run()
618+
return None

0 commit comments

Comments
 (0)