Issue with `attrs` custom `__init__` defined
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 62/100
Hướng nghiên cứu
Bắt đầu trong mypy/plugins/attrs.py, khoảng dòng 345, và lần theo cách attrs.define xác định hàm khởi tạo được sinh ra khi một lớp đã định nghĩa init. Tái hiện các ví dụ A và B từ issue, sau đó thêm kiểm thử hồi quy cho thấy cả hai hàm khởi tạo tùy chỉnh đều được tôn trọng và các lỗi kiểu đối số mong đợi được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Report
__init__ definition is ignored when generating attrs.define custom version.
To Reproduce
import attrs
@attrs.define
class A:
x: int
def __init__(self, x: str) -> None: ...
@attrs.define(init=False)
class B:
x: int
def __init__(self, x: str) -> None: ...
Expected Behavior
A(1) # error: Argument 1 to "A" has incompatible type "int"; expected "str" [arg-type]
A("1")
B(1) # error: Argument 1 to "B" has incompatible type "int"; expected "str" [arg-type]
B("1")
Actual Behavior
A("1") # error: Argument 1 to "A" has incompatible type "str"; expected "int" [arg-type]
B(1) # error: Argument 1 to "B" has incompatible type "int"; expected "str" [arg-type]
B("1")
Your Environment
- Mypy version used: mypy 1.20.0+dev
- Mypy command-line flags: file.py --show-traceback
- Mypy configuration options from
mypy.ini(and other config files): NA - Python version used: Python 3.13.9
Notes
I think the issue comes from:
https://github.com/python/mypy/blob/a86f7e3ab0ce17b9839239951430348e69c3284b/mypy/plugins/attrs.py#L345
as it does not check whether the __init__ method exists, it only checks that init=False when attrs.define is called.
- 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
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.
Issue khác của python/mypy
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug topic-configuration topic-error-reporting
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Issue tương tự
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
bancolombia/sentinel#23 ·
-
test md Đang mởCI
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100