Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Docs: socket.htons() and friends raise ValueError for negative input since 3.14

Aperta Adatta ai principianti
#159,012 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@vetrovk ci sta già lavorando.

Dal 9/10/2026.

Valutazione

Difficoltà
1/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
documentation

Direzione di ricerca

Leggi Doc/library/socket.rst ed esamina la documentazione di htons(), ntohs(), htonl() e ntohl(). Verifica la modifica descritta delle eccezioni con l’esempio o i test forniti, quindi documenta il comportamento della versione 3.14 per tutte e quattro le funzioni o nelle note di porting della versione 3.14. Il lavoro è completato quando la documentazione distingue ValueError per gli input negativi da OverflowError per i valori troppo grandi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

docs
Documentation

Doc/library/socket.rst, htons() (and ntohs()):

.. versionchanged:: 3.10
Raises OverflowError if x does not fit in a 16-bit unsigned integer.

Since 3.14 a negative argument raises ValueError ("Cannot convert negative
int"); only too-large values still raise OverflowError. htonl()/ntohl() behave the same way:

import socket
for f in (socket.htons, socket.ntohs, socket.htonl, socket.ntohl):
    for v in (-1, 1 << 40):
        try:
            f(v)
        except Exception as e:
            print(f.__name__, v, type(e).__name__)
Version -1 1 << 40
3.13 OverflowError OverflowError
3.14 / 3.15 ValueError OverflowError

This probably came with gh-132987 (__index__() support in the socket module).
It may be intended, but it is not documented, and except OverflowError
code written against the 3.10 note no longer catches negative input.
Suggested fix: add a versionchanged:: 3.14 note to all four functions, or
mention it in What's New in 3.14 (Porting).


Lingua principale
Python
Stelle
77.6k
Fork
37.6k
Merge medio
1g 10h
PR unite (30g)
573

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/cpython

Tutte le issue di python/cpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.