class decorator syntax seems to ignore dataclasses' constructor signatures
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
This code sample gives errors on the presence of f in X's constructor but not on DX's
from __future__ import annotations
from typing import Callable, Type
from dataclasses import dataclass
def clsdec(x: Callable[[int, str, object], object]) -> Type:
return x # type: ignore
@clsdec
class X(object):
def __init__(self, x: int, y: str, z: object, f: float) -> None:
pass
@clsdec
@dataclass
class DX(object):
x: int
y: str
z: object
f: float
It seems like it can't "see" the dataclass's fields somehow, despite otherwise reporting sensible errors at the call site.
In fact, clsdec(DX) gives the same error; it's only a problem when it's used in the decorator position.
Your Environment
- Mypy version used: mypy 0.961 (compiled: yes)
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: Python 3.10.4 (python.org)
- Operating system and version:
ProductName: macOS
ProductVersion: 12.4
BuildVersion: 21F79
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 chạy ví dụ được cung cấp với mypy 0.961 và so sánh các chẩn đoán cho trường hợp ở vị trí decorator với lệnh gọi trực tiếp clsdec(DX). Theo dõi việc xử lý decorator và chữ ký dataclass; hoàn tất khi việc kiểm tra chữ ký constructor là tương đương đối với cả hai dạng và được bao phủ bởi một regression test.
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