Running with --disallow-any-expr errors on exprs from "unfollowed code" even with immediate cast / assignment.

Đang mở
#4,893 3 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
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
numpy, python
Lĩnh vực
devtools

Hướng nghiên cứu

Reproduce the report using the command mypy --disallow-any-expr and the example in scratch_6.py, then compare the observed diagnostics with the linked command-line documentation. Trace how expressions from unfollowed imports are handled in the cast and annotated-assignment cases; done means both forms no longer produce the reported errors when their result is explicitly typed.

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

Mô tả

feature needs discussion topic-disallow-any topic-usability

Run mypy 0.580 on the following code with the flag:

mypy --disallow-any-expr

from typing import cast

import numpy as np # type: ignore

class C: ...

a = cast(C, np.array([1,2,3]))
b: C = np.array([1,2,3])

This yields the errors:

scratch_6.py:7: error: Expression has type "Any"
scratch_6.py:8: error: Expression has type "Any"

One each for the cast and assignment forms.

According to the docs on --disallow-any-expr (http://mypy.readthedocs.io/en/latest/command_line.html). I believe both the cast and the assignment to a typed variable should resolve the errors.

Note that I'm using numpy as my "unfollowed import" here, but the problem seems to occur with other "unfollowed" libraries I've tried as well. Substitute as convenient.

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.