A minor problem with the section "6.10.2. Membership test operations" from the language reference.
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- documentation
Hướng nghiên cứu
Đọc các mục tham chiếu ngôn ngữ “6.10.2. Membership test operations” và “3.3.13. Special method lookup”, so sánh cách diễn đạt về phép kiểm tra thành viên với ví dụ đối tượng có thể gọi trong “3.3.6.” Cập nhật phần mô tả để phản ánh chính xác việc tra cứu phương thức đặc biệt ngầm định, sau đó đối chiếu cách diễn đạt đã sửa với các ví dụ trong issue và phần văn bản tham chiếu xung quanh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 77.6k
- Fork
- 37.6k
- Merge trung bình
- 1 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 608
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/cpython
-
Docs: problem with page "msvcrt — Useful routines from the MS VC runtime"Có thể đã có người làm @jikekei đã nhận 1 ngày trước. Đang mởdocs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
python/cpython#159072 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
python/cpython#159061 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`http.client.HTTPSConnection._tunnel` raises `AttributeError: 'NoneType' object has no attribute 'encode'` when header value is `None`Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở3.14 3.15 3.16 stdlib type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
python/cpython#159044 · 14 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Docs: socket.htons() and friends raise ValueError for negative input since 3.14Có thể đã có người làm @vetrovk đã nhận 2 ngày trước. Đang mởdocs topic-socket
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
python/cpython#159012 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
stdlib topic-profiling type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của python/cpython
Issue tương tự
-
Claiming namespace `jft63`Đang mởnamespace operations
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
EclipseFdn/open-vsx.org#14043 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
feedback simulation workshop
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
githubnext/gh-aw-workshop#4455 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Triage 🩺
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Container scenario crashes without expected_recovery_time, kube DNS example uses retry_waitĐang mởneeds-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
krkn-chaos/krkn#1627 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NousResearch/hermes-agent#136483 ·
Maintainer thường phản hồi trong vòng 1 ngày