`and` fails to refine `Optional[T]`
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
- 45/100
Hướng nghiên cứu
Bắt đầu với reproducer trong optional_refine_and.py và so sánh hành vi của nó với trường hợp đối ngẫu bị lỗi trong optional_refine_or.py. Chạy trình biên dịch tĩnh trên các ví dụ để kiểm tra việc tinh chỉnh kiểu được báo cáo. Hoàn tất khi chương trình and được chấp nhận, trong khi chương trình or tiếp tục từ chối việc truyền None vào expect_int.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
a4a71ae
2021-12-29
What program did you run?
# optional_refine_and.py
# This should pass.
# This should terminate.
from typing import Optional
def expect_int(i: int) -> None:
return
def f(x: Optional[int]) -> None:
return x and expect_int(x)
assert f(None) is None
assert f(42) is None
What happened?
return x and expect_int(x)
^
compiler.errors.TypedSyntaxError: return type must be None, not Optional[int]
What should have happened?
The program should be accepted by the type checker.
Note that a dual test fails as expected.
[root@0fcdc5077884 vol]# cat Playground/conformance_suite/optional_refine_or.py
# optional_refine_or.py
# This should fail.
from typing import Optional
def expect_int(i: int) -> int:
return 42
def f(x: Optional[int]) -> int:
return x or expect_int(x)
[root@0fcdc5077884 vol]# ./python -m compiler --static Playground/conformance_suite/optional_refine_or.py
Traceback (most recent call last):
....
File "Playground/conformance_suite/optional_refine_or.py", line 10
return x or expect_int(x)
^
compiler.errors.TypedSyntaxError: type mismatch: None received for positional arg 'i', expected int
[root@0fcdc5077884 vol]#
- Ngôn ngữ chính
- Python
- Star
- 3.8k
- Fork
- 139
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
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.
Issue khác của facebookincubator/MetaPython
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
facebookincubator/MetaPython#147 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
facebookincubator/MetaPython#146 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
facebookincubator/MetaPython#145 · 4 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
facebookincubator/MetaPython#144 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
facebookincubator/MetaPython#129 · 2 bình luận ·
Tất cả issue của facebookincubator/MetaPython
Issue tương tự
-
货币战争手改优先级配置缺少列表元素类型校验(P3) Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
syfoud/Simulated_Scepter#172 ·
-
A cancelled tests run makes the coverage comment workflow fail and reports it as a red check on main Đang mởarea: ci bug perceived difficulty: 3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Nitjsefnie-Harness-Commons/daedalus#921 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ClickHouse/clickhouse-connect#1057 ·