Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tty] py312: Fix return types of set(raw|cbreak) #10785

Merged
merged 7 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions stdlib/termios.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ from _typeshed import FileDescriptorLike
from typing import Any
from typing_extensions import TypeAlias

if sys.platform != "win32":
# Must be a list of length 7, containing 6 ints and a list of NCCS 1-character bytes or ints.
_Attr: TypeAlias = list[int | list[bytes | int]]
# Must be a list of length 7, containing 6 ints and a list of NCCS 1-character bytes or ints.
_Attr: TypeAlias = list[int | list[bytes | int]] | list[int | list[bytes]] | list[int | list[int]]
# Same as _Attr for return types; we use Any to avoid a union.
_AttrReturn: TypeAlias = list[Any]

if sys.platform != "win32":
B0: int
B1000000: int
B110: int
Expand Down Expand Up @@ -252,7 +254,7 @@ if sys.platform != "win32":
XCASE: int
XTABS: int

def tcgetattr(__fd: FileDescriptorLike) -> list[Any]: ... # Returns _Attr; we use Any to avoid a union in the return type
def tcgetattr(__fd: FileDescriptorLike) -> _AttrReturn: ...
def tcsetattr(__fd: FileDescriptorLike, __when: int, __attributes: _Attr) -> None: ...
def tcsendbreak(__fd: FileDescriptorLike, __duration: int) -> None: ...
def tcdrain(__fd: FileDescriptorLike) -> None: ...
Expand Down
18 changes: 10 additions & 8 deletions stdlib/tty.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import sys
from typing import IO, Any
import termios
from typing import IO
from typing_extensions import TypeAlias

if sys.platform != "win32":
__all__ = ["setraw", "setcbreak"]
if sys.version_info >= (3, 12):
__all__ += ["cfmakeraw", "cfmakecbreak"]

_ModeSetterReturn: TypeAlias = termios._AttrReturn
else:
_ModeSetterReturn: TypeAlias = None

_FD: TypeAlias = int | IO[str]

# XXX: Undocumented integer constants
Expand All @@ -17,12 +22,9 @@ if sys.platform != "win32":
ISPEED: int
OSPEED: int
CC: int
def setraw(fd: _FD, when: int = 2) -> None: ...
def setcbreak(fd: _FD, when: int = 2) -> None: ...
def setraw(fd: _FD, when: int = 2) -> _ModeSetterReturn: ...
def setcbreak(fd: _FD, when: int = 2) -> _ModeSetterReturn: ...

if sys.version_info >= (3, 12):
# It is: `list[int, int, int, int, int, int, list[str]]
_Mode: TypeAlias = list[Any]

def cfmakeraw(mode: _Mode) -> None: ...
def cfmakecbreak(mode: _Mode) -> None: ...
def cfmakeraw(mode: termios._Attr) -> None: ...
def cfmakecbreak(mode: termios._Attr) -> None: ...