python / python/mypy

False-positive with multiple *args splats in a function call

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

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

bug
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

mypy falsely(?) reports a type error when the *args syntax is used more than once in a function call.

To Reproduce

mypy --no-incremental --config /dev/null -c '
def foobar(a: int, b: str, c: int) -> None:
    ...


foo = (1,)
bar = ("b", 3)

foobar(*foo, *bar)
'

Expected Behavior

Success: no issues found in 1 source file

Actual Behavior

<string>:9: error: Argument 2 to "foobar" has incompatible type "*Tuple[str, int]"; expected "str"
<string>:9: error: Argument 2 to "foobar" has incompatible type "*Tuple[str, int]"; expected "int"

This error goes away if I:

  • make foo an int instead of Tuple[int], and remove the splat when foobar() is called.
  • make bar two ints and make foobar() take three int arguments.
  • make foo a Tuple[str, int] and make foobar() take str, int, str, int arguments.
  • make bar just a Tuple[str] and make foobar() take int, str arguments.

Your Environment

This occurs with the standard version of mypy in Debian Testing:

$ /usr/bin/mypy --version
mypy 0.812

...as well as with the latest git revision:

$ ~/.local/pipx/venvs/mypy/bin/mypy --version
mypy 0.820+dev.8642b351cff94c471333256f9cd6867807384f01

In both cases, I'm using the Debian-provided Python 3.9.2,
on up-to-date Debian Testing.

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.

Hướng nghiên cứu

Bắt đầu bằng cách chạy lệnh mypy được cung cấp và xác nhận hai chẩn đoán cho lời gọi có nhiều tuple splat. Theo dõi việc kiểm tra các đối số của lời gọi và xử lý tuple splat, sau đó thêm độ bao phủ cho reproducer này; hoàn thành khi lệnh không báo cáo vấn đề nào mà không gây hồi quy cho các biến thể được liệt kê.

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
45/100

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.