Redefinition of function arguments can give unclear error message
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ả
With
import typing
# simulate an untyped module function
def function() -> typing.Any:
return []
def foo(var: list|str) -> list:
# insert a lot of code so that it's totally unobvious that "var" is a function parameter
var = function()
return var
You get the output
$ mypy ./test2.py
test2.py:8: error: Incompatible return value type (got "list[Any] | str", expected "list[Any]") [return-value]
Found 1 error in 1 file (checked 1 source file)
$ mypy--version
mypy 1.10.0 (compiled: yes)
which is technically correct, as var was defined as list[Any] | str as a parameter. But if you don't realise that, say there is a ton of code between where that's defined and where the return value is, you are left looking at var = function(); return var and wondering why the heck function() has been inferred to return list[Any] | str.
For a "standard" redefinition a [no-redef] warning comes out making it fairly clear. It would be great if somehow it remembered function arguments too, and then put out for this case Name "var" already defined as function parameter on line 7 which would make this very clear.
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 bản tái hiện Python được cung cấp và chạy nó bằng mypy 1.10.0 để quan sát lỗi giá trị trả về hiện tại. Theo dõi chẩn đoán [no-redef] hiện có đối với các định nghĩa lại thông thường và xác định nơi các định nghĩa lại tham số hàm được xử lý. Hoàn tất khi mẫu báo cáo tên tham số và dòng khai báo của tham số đó cùng với một chẩn đoán rõ ràng.
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
- Loại issue
- Tính năng
- Độ 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
- 45/100