A minor problem with the section "6.10.2. Membership test operations" from the language reference.
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 76/100
- issue の種類
- ドキュメント
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
言語リファレンスの「6.10.2. Membership test operations」と「3.3.13. Special method lookup」を読み、メンバーシップテストの説明を「3.3.6.」の呼び出し可能オブジェクトの例と比較してください。暗黙的な特殊メソッドの検索を正確に反映するよう説明を更新し、issue内の例と周辺のリファレンス本文に照らして改訂後の表現を確認してください。
索引モデルが issue の本文から書いたものです。
説明
Documentation
The section "6.10.2. Membership test operations" of the language reference contains the following assertion:
For user-defined classes which define the
__contains__()method,x in yreturnsTrueify.__contains__(x)returns a true value, andFalseotherwise.
But it's false; this code:
class _:
def __contains__(self, y):
return True
y = _()
y.__contains__ = lambda y: False
x=1
print(y.__contains__(x))
print(x in y)
Will yield
False
True
To be precise, the current description ignores the special method lookup described in section "3.3.13. Special method lookup". Simply changing it to type(y).__contains__(y, x) will not really solve the issue either, as the last example from section 3.3.13 shows:
class Meta(type):
def __getattribute__(*args):
print("Metaclass getattribute invoked")
return type.__getattribute__(*args)
class C(object, metaclass=Meta):
def __len__(self):
return 10
def __getattribute__(*args):
print("Class getattribute invoked")
return object.__getattribute__(*args)
c = C()
c.__len__() # Explicit lookup via instance
Class getattribute invoked
10
type(c).__len__(c) # Explicit lookup via type
Metaclass getattribute invoked
10
len(c) # Implicit lookup
10
The straightforward fix I can think of is to use the same way of describing it as, say, the "3.3.6. Emulating callable objects" section with:
object.call(self[, args...])
Called when the instance is “called” as a function; if this method is defined,x(arg1, arg2, ...)roughly translates totype(x).__call__(x, arg1, ...).
Turning our problematic expression into
For user-defined classes which define the
__contains__()method,x in yreturnsTrueif the the call to__contains__()method (which roughly translates totype(y).__contains__(y, x)) returnsTrue, otherwiseFalse.
Note that the problem is present from at least Python 3.0 onwards.
Linked PRs
- gh-159046
- 主要言語
- Python
- スター
- 77.6k
- フォーク
- 37.6k
- 平均マージ
- 1日 16時間
- マージ済み PR(30日)
- 612
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
Docs: problem with page "msvcrt — Useful routines from the MS VC runtime"対応中かも @jikekei が 3 日前に担当しました。 オープンdocs
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
python/cpython#159072 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
-
Document unpacking in generator expressions (PEP 798)対応中かも @Marwan-verse が今日担当しました。 オープンdocs
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
python/cpython#159061 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
`http.client.HTTPSConnection._tunnel` raises `AttributeError: 'NoneType' object has no attribute 'encode'` when header value is `None`再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン3.14 3.15 3.16 stdlib type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
python/cpython#159044 · コメント 17 件 ·
メンテナーはふだん 1 日以内に返信
-
Docs: socket.htons() and friends raise ValueError for negative input since 3.14対応中かも @vetrovk が 4 日前に担当しました。 オープンdocs topic-socket
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
python/cpython#159012 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
stdlib topic-profiling type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
area: agents area: docs good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
openapi/gknowledge#23 ·
-
get() for StrEnum対応中かも @FeJo5952 が今日担当しました。 オープンgood first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
collective/icalendar#1921 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Improvement Python Spans
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
getsentry/sentry-python#7994 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
alphagov/notifications-api#5004 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
equinor/radix-flux#3922 ·
メンテナーはふだん 1 日以内に返信