(inter-)dependent variable types
Đang mở
Chưa có ai nhận issue này.
feature
needs discussion
priority-2-low
- 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ả
I'm not sure how to entitle this, but I think it's a dependent type.
- Are you reporting a bug, or opening a feature request? yes
- Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
from typing import Tuple, Union
def x() -> Union[Tuple[int, int], Tuple[str, str]]:
...
a, b = x()
if isinstance(b, int):
reveal_type(a) # can only be int but is reported as Union[int, str]
- What is the actual behavior/output?
type is reported asUnion[int, str] - What is the behavior/output you expect?
type ofacan only beintgiven the return type signature - What are the versions of mypy and Python you are using? 7.20
Do you see the same issue after installing mypy from Git master? yes - What are the mypy flags you are using? (For example --strict-optional)
python_version=3.7
I'm assuming this would be a difficult change, but I figured I'd open an issue for the sake of having a record, and in the meantime I can use assert isinstance()
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
Bắt đầu với bản tái hiện Python tối thiểu trong issue và xác minh đầu ra reveal_type hiện tại dưới cấu hình Python 3.7 đã nêu. Thay đổi sẽ hoàn tất khi việc thu hẹp b thành int cũng thu hẹp a thành int, đồng thời giữ nguyên trường hợp str tương ứng và hành vi hiện tại đối với các union 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
- compilers
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 30/100