python / python/mypy

enumerate(Union[Sequence, Sequence])

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

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

feature needs discussion topic-join-v-union topic-type-variables
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

Mô tả

  • Are you reporting a bug, or opening a feature request?
    Bug
  • Please insert below the code you are checking with mypy.
from typing import Sequence, Union

def baz(idx: int, arg: Union[int, str]) -> None:
    pass

def foo(the_list: Union[Sequence[int], Sequence[str]]) -> None:
    for idx, val in enumerate(the_list):
        reveal_type(idx)
        reveal_type(val)
        baz(idx, val)
  • What is the actual behavior/output?
foo.py:8: note: Revealed type is 'builtins.int'
foo.py:9: note: Revealed type is 'builtins.object*'
foo.py:10: error: Argument 2 to "baz" has incompatible type "object"; expected "Union[int, str]"
  • What is the behavior/output you expect?
foo.py:8: note: Revealed type is 'builtins.int'
foo.py:9: note: Revealed type is 'Union[int, str]'
  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?
    0.761, 0.770 and master all have the same result.
  • What are the mypy flags you are using? (For example --strict-optional)
    --strict

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

Tái hiện ví dụ trong foo.py bằng mypy và các cờ --strict đã được báo cáo, sau đó kiểm tra đường dẫn suy luận kiểu cho enumerate trên một union các sequence. Hoàn tất khi reveal_type(val) báo cáo Union[int, str] và lời gọi baz được chấp nhận mà không làm yếu các kiểm tra không liên quan.

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

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.