`and` fails to refine `Optional[T]`

Đang mở
#63 0 bình luận 1 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
45/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
compilers

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ả

sp-correctness staticpython

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

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 facebookincubator/MetaPython

Tất cả issue của facebookincubator/MetaPython

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.