Incompatible typing for `logging.Formatter.converter` and `time.gmtime`/`time/localtime` ?
Đang mở
Chưa có ai nhận issue này.
stubs: false positive
- Ngôn ngữ chính
- Python
- Star
- 5.1k
- Fork
- 2.1k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 82
Mô tả
The typing for converter here is as follows:
converter: Callable[[float | None], struct_time]
And the typing for time.gmtime/time.localtime here is:
def gmtime(seconds: float | None = None, /) -> struct_time: ...
def localtime(seconds: float | None = None, /) -> struct_time: ...
Yet when I try to typecheck this code:
import logging
import time
class UTCFormatter(logging.Formatter):
converter = time.gmtime
I get the following error:
$ mypy main.py
main.py:5: error: Incompatible types in assignment (expression has type "Callable[[], struct_time]", base class "Formatter" defined the type as "Callable[[float | None], struct_time]") [assignment]
Found 1 error in 1 file (checked 1 source file)
I tested this on a fresh python3.13 venv with the following deps installed:
mypy==1.18.2
mypy_extensions==1.1.0
pathspec==0.12.1
typing_extensions==4.15.0
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 stdlib/logging/init.pyi và stdlib/time.pyi tại các định nghĩa được tham chiếu, sau đó tái hiện phép gán bằng mypy với ví dụ trong issue. Kiểm tra lý do hai chú thích callable bị coi là không tương thích và cập nhật phần kiểu hóa stub liên quan để ví dụ được kiểm tra kiểu mà không có lỗi phép gán.
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ó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 50/100