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

Đang mở
#22,298 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
compilers

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện đầu ra v2.26.2 tsg-python cho class Bar(list[int]): pass, sau đó theo dõi cách parser xử lý nút Subscript khi xây dựng các base của lớp. Hoàn tất khi base generic tạo ra một cạnh bases và CodeQL nhận diện quan hệ Bar -> list[int], trong khi trường hợp không generic hiện có vẫn nguyên vẹn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 11 giờ
Pull request đã merge (30 ngày)
129

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của github/codeql

Tất cả issue của github/codeql

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.