Skip to content

TimeoutError has errno and strerror attributes set to None #109601

Open
@aminalaee

Description

@aminalaee

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions