appending `#type:ignore` to an import does more than skipping analyzing the import
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug Report
I ran into relatively low priority unexpected behavior. I have this code
from anytree import NodeMixin # type:ignore
from typing import *
from abc import abstractmethod
class IFoo(Protocol):
@abstractmethod
def foo(self) -> None:
raise NotImplementedError()
class Foo(IFoo, NodeMixin):
...
def main() -> None:
a = Foo()
if __name__ == '__main__':
main()
anytree is a third-party package. When I run mypy on it, I expect that static analysis on anytree to be skipped, and static analysis on Foo to fail with something like "Foo needs to implement abstractmethod foo". What actually happens is that mypy exits with success saying 0 errors were found.
What I've tried to do to cause the expected behavior to occur was to use stubgen on the anytree install which generated stubs in the project folder, run mypy --install-types to install type hints for a dependency of anytree, and configure a mypy.ini in project root to point to the stubs. All of which was simple to do, but kind of tedious.
I also read https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports where it mentioned
This can result in mypy failing to warn you about errors in your code. Since operations on Any result in Any, these dynamic types can propagate through your code, making type checking less effective. See Dynamically typed code for more information.
So I guess the suppression of static checking is leaking from anytree.NodeMixin into Foo.
Actual Behavior
mypy exits with success, 0 errors
Your Environment
I'm on Windows.
- Mypy version used: 0.990
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.10.4
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.
Hướng nghiên cứu
Bắt đầu với reproducer trong issue và chạy mypy 0.990 để xác nhận rằng việc suppress import cũng ẩn lỗi phương thức abstract trong Foo. Theo dõi cách xử lý # type: ignore trên các import và thêm một regression test cho thấy import bị bỏ qua mà không suppress các lỗi trong code sử dụng lớp cơ sở được import; hoàn thành khi ví dụ báo cáo việc thiếu triển khai foo của Foo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- compilers, devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100