Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#159,012 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@vetrovk がすでに取り組んでいます。

2026年10月9日 から。

  • #159047 @vetrovk による — オープン

評価

難易度
1/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
documentation

調査の方向性

Doc/library/socket.rstを読み、htons()、ntohs()、htonl()、ntohl()のドキュメントを確認してください。説明されている例外の変更を、提示された例またはテストと照合して確認し、その後、4つすべての関数について、または3.14の移植に関する注記に、3.14での動作を記述してください。ドキュメントで、負の入力に対するValueErrorと大きすぎる値に対するOverflowErrorが区別されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

docs topic-socket
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).


Linked PRs
  • gh-159047
主要言語
Python
スター
77.6k
フォーク
37.6k
平均マージ
1日 16時間
マージ済み PR(30日)
612

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。