Always complain if returning a value if annotated to return None

Đang mở
#1,509 3 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
compilers, devtools

Hướng nghiên cứu

Start by reproducing the issue's two-function example and trace how mypy analyzes a return statement in a function annotated to return None when the returned expression has type Any. Done means mypy reports this return as an error while preserving the intended handling of valid None returns.

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

Mô tả

priority-1-normal topic-strict-optional

Mypy doesn't complain about this code that returns a value in a function declared to return None, since the return value is Any:

def f() -> None:
    return g()   # oops, but no error

def g():
    return 1

I think that mypy could complain about the return statement even if the value has type Any. The current behavior is not inconsistent or incorrect, but probably not optimal.

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.