Skip to content

OSError stubs don't match actual types for TimeoutError subclass #9864

Description

@chrisdahlberg

OSError is currently stubbed as:

classOSError(Exception):
errno: intstrerror: str# filename, filename2 are actually str | bytes | Nonefilename: Anyfilename2: Anyifsys.platform=="win32":
winerror: int

The CPython TimeoutError subclass of it returned by socket functions will sometimes have errno and strerrorNone depending on which underlying syscall detected the timeout (select() reporting 0 sockets ready vs something failing with ETIMEDOUT)

Example:

importsockets=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.1)
try:
# Try to connect to a host that doesn't exist on your# networks.connect(("10.10.10.10", 22))
exceptOSErrorasex:
print(repr(ex))
print(f"errno is {type(ex.errno)} - {ex.errno}")
print(f"strerror is {type(ex.strerror)} - {ex.strerror}")

produces

TimeoutError('timed out')
errno is <class 'NoneType'> - None
strerror is <class 'NoneType'> - None

on
Python 3.10.9 | packaged by conda-forge | (main, Feb 2 2023, 20:14:58) [MSC v.1929 64 bit (AMD64)]

The CPython implementation looks like it would do the same on all platforms


(@srittau 2024-09-02) Deferred until python/cpython#109601 and python/cpython#109714 are decided on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: deferredIssue or PR deferred until some precondition is fixed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions