[Generics] Multiple callable arguments to function generate incompatible type error

Đang mở
#3,568 4 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả 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 generic and Callable example with the stated mypy command, comparing the two-argument and one-argument signatures. Trace the type-checking path for callable argument inference; done means the two-argument form no longer reports the misleading incompatible-type error while the behavior remains covered by a regression test.

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

Mô tả

from typing import TypeVar, Generic, Callable

A = TypeVar('A')
B = TypeVar('B')
E = TypeVar('E', bound=BaseException)


class Child(Generic[A]):
    def __init__(self, x):
        # type: (E) -> None
        self.x = x

    def fun(self, s, f):
        # type: (Callable[[A], Child[B]], Callable[[E], Child[B]]) -> Child[B]
        return f(self.x)  # <----- error here
test_py.py:15: error: Argument 1 has incompatible type "E"; expected "E"

Kind of misleading, and I think it is a bug.
Interesting thing is that when you remove the 's' argument and it's part in type comment so it becomes like this :

    def fun(self, f):
        # type: (Callable[[E], Child[B]]) -> Child[B]
        return f(self.x)

then there is no error.

command: <file_path> --strict-optional --warn-no-return --warn-redundant-casts --check-untyped-defs --disallow-untyped-defs --py2
mypy version: 0.511
os: Ubuntu 16.10

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.