Detect if required string literal escapes are missing from a type

Đang mở
#948 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ó
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
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
compilers

Hướng nghiên cứu

Start by tracing mypy's semantic analysis for forward references and the handling of quoted versus unquoted type names. Check how class definitions and cyclic imports are represented, and account for the issue's note about type aliases. Done means reporting missing required string-literal escapes, initially within a single module and eventually across cyclic imports.

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

Mô tả

feature priority-1-normal topic-quoted-annotations topic-usability

Mypy should complain about code that isn't using string literal escaped when they are required:

class A:
    def (self) -> A: ...   # Should be an error; string literal escape required

Initially we could only detect these cases within a single module. A more general solution would also detect string literal types needed due to cyclic imports.

A simple implementation idea:

  • Tag each instance type with information on whether the type is quoted or not.
  • During semantic analysis, if a type is unquoted but the definition line for the type/class is in the current file but at a later line number, complain.
  • The definition line for a class is actually the line after the end of the class definition. Alternatively, treat classes that are currently being analyzed specially.

We also need deal with type aliases, but this isn't needed for the first iteration.

I think that somebody started working on this a while back, but I can't remember the details. Maybe there is an existing issue as well?

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.