python / python/cpython

symtable entries should expose the scope attributes computed by the analysis

未關閉
#153,849 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

3.16 stdlib type-feature
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Feature or enhancement

The symbol table analysis computes a number of per-scope attributes that the compiler relies on, but does not expose them. I propose to add them as read-only attributes of the symbol table entries: is_generator, is_coroutine, has_annotations, has_conditional_annotations, needs_class_closure, needs_classdict, can_see_class_scope and annotation_block.

>>> import _symtable
>>> top = _symtable.symtable("async def f(): yield", "<string>", "exec")
>>> f = next(c for c in top.children if c.name == "f")
>>> f.is_generator, f.is_coroutine
(True, True)

A consumer currently has to re-derive these by walking the AST and replicating the exact rules of Python/symtable.c, which can change between versions. Trivially derivable attributes (like whether a function has a *args parameter or a docstring) are left out, but can be added later.

Linked PRs
  • gh-153850

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先檢視連結的 PR gh-153850,然後閱讀 Python/symtable.c 中的作用域分析,issue 將其識別為這些屬性的來源。確認所要求的值是以符號表項目的唯讀屬性形式公開的,並確認連結的 PR 涵蓋了所述情況。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
compilers
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。