Type field declared in multiple flows as common base

Đang mở
#5,111 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.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
devtools

Hướng nghiên cứu

The issue names no files, tests, or entry points. Start by reviewing the conditional-assignment examples and the requested common-base inference, then determine the intended typing behavior for optional and related model types. Done means the desired inference is defined and supported without requiring either explicit annotation form.

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

Mô tả

feature topic-type-narrowing

In this code:

if condition:
  s = get_str()
else:
  s = get_optional_str()

we currently need to add hints, i.e. (a)

if condition:
  s: Optional[str] = get_str()
else:
  s = get_optional_str()

or (b)

s: Optional[str]
if condition:
  s = get_str()
else:
  s = get_optional_str()

Both (a) and (b) seem overly verbose to me, for what seems like a common pattern. If the optionality of s serves a problem for the code that's to follow, that's what mypy should alert us about.

Perhaps optionality is actually somewhat of a special case. A more natural application of this logic would allow for:

if condition:
   model = get_foo_model()  # FooModel
else:
   model = get_bar_model()  # BarModel
# model is Model
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.