library symtable.SymbolTable.is_nested() description differs from Cpython implementation.
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 20/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- documentation
Hướng nghiên cứu
Trước tiên, hãy xem xét PR được liên kết gh-151901, sau đó so sánh symtable và kiểm tra tài liệu dựa trên hành vi CPython đã nêu cùng flag CO_NESTED. Issue để ngỏ cách giải quyết: hoặc đồng bộ hóa phần triển khai và thêm compiler tests, hoặc sửa tài liệu và có thể đánh dấu tính năng là deprecated.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The documentation says
is_nested()
Return True if the block is a nested class or function.
The cpython implementation of symtable.c sets the corresponding flag only if the block is nested somewhere inside a function. This would include, for example, a scope inside a class inside a function.
Thus
def f(): # false
def g(): # true
def h(): # true
class C: # true
class B: # true
def h(): # true
class C: # true
class A: # false
def g(): # false !!
def h(): # true
class C: # true
class B: # false !!
def h(): # false !!
class C: # false !!
The value is the same as the CO_NESTED bit in the code object's co_flags member.
The flag is also documented (similarly incorrectly) in the inspect module documentation.
I would recommend deprecating this feature. The documentation for co_flags says that
bits 0x10 and 0x1000 were used in earlier versions of Python.
0x10 is the CO_NESTED bit. I would guess that nobody uses CO_NESTED or SymbolTable.is_nested().
Alternatives:
- Change the behavior in Cpython to agree with the documentation. A class nested in another scope should also have CO_NESTED set. Make a test case for the compiler, to ensure that other implementations follow the same definition.
- Correct the documentation for symtable and inspect modules. Possibly also deprecate the feature.
Linked PRs
- gh-151901
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 558
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 pending
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
build type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
stdlib topic-email type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Tất cả issue của python/cpython
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
zostera/django-bootstrap4#894 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
use-agent-os/agent-os#3276 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
zilliztech/memsearch#759 ·