Use alias names in error messages

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

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/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
devtools

Hướng nghiên cứu

Start by reproducing the supplied tmp.py example with mypy and inspect how its diagnostic renders the expected type. Trace the relevant type-alias and error-reporting entry points, then verify that diagnostics use the alias name while also showing its expansion, without changing unrelated messages.

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-type-alias topic-usability

Given:

from typing import Tuple
from math import hypot

Point = Tuple[float, ...]
Centroid = Point

def dist(p: Centroid, q: Point) -> float:
    px, py = p
    qx, qy = q
    return hypot(px - qx, py - qy)

print( dist('xyz', (3.5, 7.2)) )

mypy detect the incorrect first argument:

$ mypy tmp.py
tmp.py:12: error: Argument 1 to "dist" has incompatible type "str"; expected Tuple[float, ...]

However, it would be much nicer is the error reporting could have used the alias name:

tmp.py:12: error: Argument 1 to "dist" has incompatible type "str"; expected "Centroid", which expands to Tuple[float, ...]

I realize it may be easy to do, but it would improve the usability of aliases.

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.