Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

[Python] tsg-parser fails to extract generic base class relations

未關閉
#22,298 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
冷清
技術堆疊
python
領域
compilers

研究方向

首先重現 class Bar(list[int]): pass 的 v2.26.2 tsg-python 輸出,然後追蹤 parser 在建構類別基底時如何處理 Subscript 節點。完成的標準是:泛型基底產生一條 bases 邊,且 CodeQL 能辨識 Bar -> list[int] 關係,同時現有的非泛型情況維持不變。

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

描述

question

Working with typed base classes in Python (see #22291) I realised that the toolchain seems to drop generic base classes (e.g. list[int] in class Bar(list[int]):) at some point. That is, in the example code

class Foo(list): pass

class Bar(list[int]): pass

CodeQL knows the Foo -> list relation but not the Bar -> list[int] relation.


As far as I could trace it, the relation is already lost in the tsg-python parser. Using the v2.26.2 toolchain, the source code class Bar(list): pass produces the following tsg-python output (assignment nodes removed for brevity):

node 4
  _kind: "Name"
  _location: [0, 10, 0, 14]
  ctx: "load"
  variable: "list"
node 5
  _kind: "ClassExpr"
  _location: [0, 0, 0, 21]
  _location_end: [0, 16]
  inner_scope: [graph node 6]
  name: "Bar"
edge 5 -> 4
  bases: 0
node 6
  _kind: "Class"
  _location: [0, 0, 0, 21]
  _location_end: [0, 16]
  name: "Bar"
edge 6 -> 1
  body: 0

Now if the code is extended for a generic subscription as class Bar(list[int]): pass produces the following tsg-python output (assignment nodes removed for brevity):

node 4
  _kind: "Name"
  _location: [0, 10, 0, 14]
  ctx: "load"
  variable: "list"
node 5
  _kind: "Name"
  _location: [0, 15, 0, 18]
  ctx: "load"
  variable: "int"
node 6
  _kind: "Subscript"
  _location: [0, 10, 0, 19]
  ctx: "load"
  index: [graph node 5]
  value: [graph node 4]
node 7
  _kind: "ClassExpr"
  _location: [0, 0, 0, 26]
  _location_end: [0, 21]
  inner_scope: [graph node 8]
  name: "Bar"
node 8
  _kind: "Class"
  _location: [0, 0, 0, 26]
  _location_end: [0, 21]
  name: "Bar"
edge 8 -> 1
  body: 0

Notice that the type subscription is parsed (nodes 4, 5, 6) but the edge n -> m node for the bases: 0 relation is absent.

主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 17 小時
30 天內合併 PR
145

貢獻指南

開啟貢獻指南

從這裡開始

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

github/codeql 的其他 Issue

查看 github/codeql 的全部 Issue

相似的 Issue

更多 Compilers Issue

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

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