Skip to content

Fix stubtest of pyserial #9722

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

Merged
merged 2 commits into from
Feb 19, 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
11 changes: 3 additions & 8 deletions stubs/pyserial/@tests/stubtest_allowlist_darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@ serial.tools.list_ports_windows # Windows only

# Error: is inconsistent
# ======================
# These are positional only argument in the stub because they inherit from io.RawIOBase
# but at runtime they are normal arguments that don't have consistent names.
# Methods defined with positional-only argument in the stub because they inherit from
# io.RawIOBase but at runtime they are normal arguments that don't have consistent
# names.
serial.PosixPollSerial.read
serial.VTIMESerial.read
serial.serialposix.Serial.read
serial.serialposix.Serial.write
serial.serialposix.PosixPollSerial.read
serial.serialposix.VTIMESerial.read

# Error: is missing from the stub
# ===============================
# TODO: maybe add these
serial.tools.list_ports_linux.SysFS
serial.tools.list_ports_linux.comports

# intended to be private aliases
serial.tools.list_ports_posix.plat
serial.serialposix.plat
5 changes: 3 additions & 2 deletions stubs/pyserial/@tests/stubtest_allowlist_linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ serial.tools.list_ports_windows # Windows only

# Error: is inconsistent
# ======================
# These are positional only argument in the stub because they inherit from io.RawIOBase
# but at runtime they are normal arguments that don't have consistent names.
# Methods defined with positional-only argument in the stub because they inherit from
# io.RawIOBase but at runtime they are normal arguments that don't have consistent
# names.
serial.PosixPollSerial.read
serial.VTIMESerial.read
serial.serialposix.Serial.read
Expand Down
21 changes: 3 additions & 18 deletions stubs/pyserial/@tests/stubtest_allowlist_win32.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,8 @@ serial.tools.list_ports_posix # Posix only

# Error: is inconsistent
# ======================
# These are positional only argument in the stub because they inherit from io.RawIOBase
# but at runtime they are normal arguments that don't have consistent names.
# Methods defined with positional-only argument in the stub because they inherit from
# io.RawIOBase but at runtime they are normal arguments that don't have consistent
# names.
serial.serialwin32.Serial.read
serial.serialwin32.Serial.write

# Missing from the stub (TODO: add these)
# =======================================
serial.win32._SECURITY_ATTRIBUTES.\w+
serial.win32._OVERLAPPED.\w+
serial.win32._DCB.\w+
serial.win32._COMSTAT.\w+
serial.win32._COMMTIMEOUTS.\w+
serial.win32.N11_OVERLAPPED4DOLLAR_48E.\w+
serial.win32.N11_OVERLAPPED4DOLLAR_484DOLLAR_49E.\w+
serial.win32.CreateEventW
serial.win32.CreateFileW
serial.tools.list_ports_linux.SysFS
serial.tools.list_ports_linux.comports
serial.tools.list_ports_windows.SP_DEVINFO_DATA.\w+
serial.tools.list_ports_windows.GUID.\w+
19 changes: 8 additions & 11 deletions stubs/pyserial/serial/tools/list_ports_linux.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import sys

from serial.tools.list_ports_common import ListPortInfo

if sys.platform == "linux":
class SysFS(ListPortInfo):
usb_device_path: str | None
device_path: str | None
subsystem: str | None
usb_interface_path: str | None
def __init__(self, device: str) -> None: ...
def read_line(self, *args: str) -> str | None: ...
class SysFS(ListPortInfo):
usb_device_path: str | None
device_path: str | None
subsystem: str | None
usb_interface_path: str | None
def __init__(self, device: str) -> None: ...
def read_line(self, *args: str) -> str | None: ...

def comports(include_links: bool = ...) -> list[SysFS]: ...
def comports(include_links: bool = ...) -> list[SysFS]: ...
13 changes: 11 additions & 2 deletions stubs/pyserial/serial/tools/list_ports_windows.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ if sys.platform == "win32":
ACCESS_MASK = DWORD
REGSAM = ACCESS_MASK

class GUID(ctypes.Structure): ...
class SP_DEVINFO_DATA(ctypes.Structure): ...
class GUID(ctypes.Structure):
Data1: ctypes._CField
Data2: ctypes._CField
Data3: ctypes._CField
Data4: ctypes._CField

class SP_DEVINFO_DATA(ctypes.Structure):
cbSize: ctypes._CField
ClassGuid: ctypes._CField
DevInst: ctypes._CField
Reserved: ctypes._CField
PSP_DEVINFO_DATA: type[ctypes._Pointer[SP_DEVINFO_DATA]]
PSP_DEVICE_INTERFACE_DETAIL_DATA = ctypes.c_void_p
setupapi: ctypes.WinDLL
Expand Down
80 changes: 71 additions & 9 deletions stubs/pyserial/serial/win32.pyi
Original file line number Diff line number Diff line change
@@ -1,28 +1,84 @@
import sys
from ctypes import Structure, Union, _NamedFuncPointer, _Pointer, c_int64, c_ulong, c_void_p
from ctypes import Structure, Union, _CField, _NamedFuncPointer, _Pointer, c_int64, c_ulong, c_void_p
from ctypes.wintypes import DWORD
from typing_extensions import TypeAlias

if sys.platform == "win32":
def is_64bit() -> bool: ...

ULONG_PTR: c_int64 | c_ulong
ULONG_PTR: type[c_int64 | c_ulong]

class _SECURITY_ATTRIBUTES(Structure): ...
class _SECURITY_ATTRIBUTES(Structure):
nLength: _CField
lpSecurityDescriptor: _CField
bInheritHandle: _CField
LPSECURITY_ATTRIBUTES: type[_Pointer[_SECURITY_ATTRIBUTES]]
CreateEvent: _NamedFuncPointer
CreateFile: _NamedFuncPointer
# The following are included in __all__ but their existence is not guaranteed as
# they are defined in a try/except block. Their aliases above are always defined.
CreateEventW: _NamedFuncPointer
CreateFileW: _NamedFuncPointer

class _OVERLAPPED(Structure): ...
class _OVERLAPPED(Structure):
Internal: _CField
InternalHigh: _CField
Offset: _CField
OffsetHigh: _CField
Pointer: _CField
hEvent: _CField
OVERLAPPED: TypeAlias = _OVERLAPPED

class _COMSTAT(Structure): ...
class _COMSTAT(Structure):
fCtsHold: _CField
fDsrHold: _CField
fRlsdHold: _CField
fXoffHold: _CField
fXoffSent: _CField
fEof: _CField
fTxim: _CField
fReserved: _CField
cbInQue: _CField
cbOutQue: _CField
COMSTAT: TypeAlias = _COMSTAT

class _DCB(Structure): ...
class _DCB(Structure):
DCBlength: _CField
BaudRate: _CField
fBinary: _CField
fParity: _CField
fOutxCtsFlow: _CField
fOutxDsrFlow: _CField
fDtrControl: _CField
fDsrSensitivity: _CField
fTXContinueOnXoff: _CField
fOutX: _CField
fInX: _CField
fErrorChar: _CField
fNull: _CField
fRtsControl: _CField
fAbortOnError: _CField
fDummy2: _CField
wReserved: _CField
XonLim: _CField
XoffLim: _CField
ByteSize: _CField
Parity: _CField
StopBits: _CField
XonChar: _CField
XoffChar: _CField
ErrorChar: _CField
EofChar: _CField
EvtChar: _CField
wReserved1: _CField
DCB: TypeAlias = _DCB

class _COMMTIMEOUTS(Structure): ...
class _COMMTIMEOUTS(Structure):
ReadIntervalTimeout: _CField
ReadTotalTimeoutMultiplier: _CField
ReadTotalTimeoutConstant: _CField
WriteTotalTimeoutMultiplier: _CField
WriteTotalTimeoutConstant: _CField
COMMTIMEOUTS: TypeAlias = _COMMTIMEOUTS

GetLastError: _NamedFuncPointer
Expand Down Expand Up @@ -94,6 +150,12 @@ if sys.platform == "win32":
EV_BREAK: int
PURGE_RXCLEAR: int

class N11_OVERLAPPED4DOLLAR_48E(Union): ...
class N11_OVERLAPPED4DOLLAR_484DOLLAR_49E(Structure): ...
class N11_OVERLAPPED4DOLLAR_48E(Union):
Offset: _CField
OffsetHigh: _CField
Pointer: _CField

class N11_OVERLAPPED4DOLLAR_484DOLLAR_49E(Structure):
Offset: _CField
OffsetHigh: _CField
PVOID: TypeAlias = c_void_p