Open
Description
Bug report
Bug description:
According to the docs OSError
https://docs.python.org/3/library/exceptions.html#OSError has the attributes errno
and strerror
(integer and string respectively) set on this class and sub-classes like TimeoutError
https://docs.python.org/3/library/exceptions.html#TimeoutError
And the TimeoutError
is mapped to errno
https://docs.python.org/3/library/errno.html#errno.ETIMEDOUT which has a default value depending on the OS.
Is this a bug in how the TimeoutError
is raised? Or can the attributes be None
which should be documented?
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.1)
try:
s.connect(("10.10.10.10", 22))
except OSError as ex:
print(repr(ex))
print(f"errno is {type(ex.errno)} - {ex.errno}")
print(f"strerror is {type(ex.strerror)} - {ex.strerror}")
# But the `FileNotFoundError` has the correct attributes are set
import os
try:
os.listdir("non_existing_path")
except OSError as ex:
print(repr(ex))
print(f"errno is {type(ex.errno)} - {ex.errno}")
print(f"strerror is {type(ex.strerror)} - {ex.strerror}")
Ref: python/typeshed#9864
CPython versions tested on:
3.11
Operating systems tested on:
Linux