python / python/typeshed

OSError stubs don't match actual types for TimeoutError subclass

Offen
#9,864 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

status: deferred
Vorherrschende Sprache
Python
Sterne
5.1k
Forks
2.1k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
82

Beschreibung

OSError is currently stubbed as:

class OSError(Exception):
    errno: int
    strerror: str
    # filename, filename2 are actually str | bytes | None
    filename: Any
    filename2: Any
    if sys.platform == "win32":
        winerror: int

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

Example:

import socket
s = 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
    # network
    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}")

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Untersuche die OSError-Deklaration und reproduziere das Socket-Timeout-Beispiel, um die Laufzeitwerte von errno und strerror zu bestätigen. Prüfe zuerst python/cpython#109601 und python/cpython#109714; fertig, wenn der Stub dem festgelegten CPython-Verhalten entspricht, einschließlich möglicher None-Werte.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.