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

TimeoutError has errno and strerror attributes set to None #109601

Open
aminalaee opened this issue Sep 20, 2023 · 0 comments
Open

TimeoutError has errno and strerror attributes set to None #109601

aminalaee opened this issue Sep 20, 2023 · 0 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@aminalaee
Copy link
Contributor

aminalaee commented Sep 20, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants