Preserve annotations and inferred types when generating stubs

Đang mở
#3,475 3 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ó
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
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
tooling

Hướng nghiên cứu

Start by examining stubgen and the mypy AST flow for a target module or package. Determine how an equivalent mypy run could provide inferred types and how generated stubs would handle Python versions and platform-specific definitions. Done means producing annotated stubs that preserve explicit and inferred types, with the platform and version behavior resolved.

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

Mô tả

needs discussion topic-stubgen

If a user maintains a 3rd party library module that is type checked using mypy, there is no easy to way to automatically generate annotated typeshed stubs for that library, even though this could be pretty useful. We could perhaps extend stubgen to do this job.

Here's how this could work internally:

  • Do the equivalent of a mypy run against a target module/package.
  • Generate stubs based on the mypy AST, including inferred types.

The main difference from previous stubgen related proposals would be the inclusion of inferred types in the stubs. For example, consider this program:

x = 0
a = [x]

The generated stub could look like this:

from typing import List

x: int
a: List[int]

Here are a few things that complicate this task:

  • It may be hard to generate stubs that work with both Python 2 and 3. However, maybe it's okay to generate separate stubs for 2 and 3, since the stubs hopefully won't need a lot of manual review as they are automatically generated.
  • It may be hard to include platform-specific definitions. One approach would be to generate separate ASTs for all supported platforms and somehow merge them, generating conditional platform checks automatically.
Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Merge trung bình
1 ngày 18 giờ
Pull request đã merge (30 ngày)
54

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 python/mypy

Tất cả issue của python/mypy

Issue tương tự

Thêm issue về Python

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.