Wrong "Too many arguments" errors with tuple unpacking
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug Report
I'm getting wrong or misleading "Too many arguments" errors when using tuple unpacking in function calls.
To Reproduce
from typing import Tuple
def x(x: int, y: int) -> None:
print(x, y)
def foo1(t: tuple) -> None:
x(*t[:1], 1)
def foo2(t: tuple) -> None:
x(*t[:2])
def foo3(t: Tuple[int]) -> None:
x(*t[:1], 1)
mypy reports:
$ mypy sandbox.py
sandbox.py:7: error: Too many arguments for "x"
Found 1 error in 1 file (checked 1 source file)
(Line 7 is the call to x in foo1)
Expected Behavior
The call to x in foo1 will never have too many arguments -- it has either 1 (if t is empty) or 2 (if t is not empty). I would have expected an error regarding the possibility of t being empty (i.e. "Potentially not enough arguments").
Also I think that foo1 and foo2 share the same issues regarding their calls of x, so I would have expected to get the same errors for both of them.
Actual Behavior
The call to x in foo1 is reported, but the call to x in foo2 isn't. Interestingly, fixing the tuple length (as in foo3) seems to fix the issue.
Your Environment
- Mypy version used: 0.790
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.8.5
- Operating system and version: Ubuntu 18.04.5
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện các ví dụ trong sandbox.py bằng mypy trên môi trường Python 3.8.5 được báo cáo và so sánh các chẩn đoán cho foo1, foo2 và foo3. Truy vết việc kiểm tra đối số khi giải nén tuple bắt đầu từ lời gọi bị lỗi, sau đó thêm phạm vi kiểm thử hồi quy cho cách xử lý dự kiến của từng ví dụ và xác minh rằng các chẩn đoán nhất quán.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100