Decorator becomes untyped when it accepts an object of the same type as a certain global.
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
A decorator becomes untyped when it accepts an argument for which we have another instance, globally defined and referred to in the same scope.
The comments in the example should make the bug much more clear.
I had no idea how to describe this issue or search for it, so no idea whether it was reported before.
To Reproduce
from typing import Callable
class Something:
pass
def decorator(buffer: Something) -> Callable[[Callable[[], None]], Callable[[], None]]:
return lambda x: x
def main() -> None:
something # Comment out this line and everything is fine.
another_something = Something()
@decorator(another_something)
def func() -> None:
return
something = Something() # Move this above `main` and everything is fine.
Expected Behavior
The code snippet should pass.
Actual Behavior
$ mypy --strict /tmp/test.py
test.py:16: error: Untyped decorator makes function "func" untyped
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.982
- Mypy command-line flags: --strict
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9.13
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 bằng cách tái hiện đoạn mã với mypy --strict và so sánh hành vi khi something toàn cục bị xóa hoặc được chuyển lên trên main. Theo dõi quá trình suy luận kiểu của decorator và đường dẫn phân giải tên liên quan trong ví dụ này. Được xem là hoàn tất khi đoạn mã ban đầu vượt qua kiểm tra strict mà không báo cáo decorator không có kiểu.
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
- 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