Dataclass constructors defaults don't solve type parameters
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 57/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- developer-experience, testing-qa
Hướng nghiên cứu
Start by reading the generated dataclass constructor logic and the generic argument solving path in Pyrefly; the issue does not name specific source files or tests. Use the Python example in the issue as a regression case: Generated() should reveal Generated[int], while Generated(5) should continue to reveal Generated[int]. Add or update a focused type-checker test for those results.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the Bug
Consider this code:
from dataclasses import dataclass
from typing import reveal_type
class Explicit[T]:
def __init__(self, x: T = 5) -> None:
self.x = x
@dataclass
class Generated[T]:
x: T = 5 # pyrefly: ignore[bad-assignment]
reveal_type(Explicit()) # Explicit[int]
reveal_type(Generated()) # Generated[@_] — expected Generated[int]
reveal_type(Generated(5)) # Generated[int]
There's a gap in our generated dataclass constructor logic. The default value for x is not actually affecting how calls solve. It's clear from Explicit that we intend for default constructor arguments to solve generic tparams when suitable, but in Generated we ignore the fact that the default of 5 means T ought to solve to int.
Note that it's possible to make this example work with T = int, a tparam-level default. But that's not a good solution - as a rule we don't want to use tparam-level defaults (which are an advanced feature and have some probably-undesirable side effects, like making a bare Generated mean Generated[int] rather than Generated[Any]) for a case where they aren't necessary
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
- Ngôn ngữ chính
- Rust
- Star
- 7.2k
- Fork
- 578
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc 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 facebook/pyrefly
-
False positive: `Protocol` with `EXCLUDED_ATTRIBUTES` cannot be used with `issubclass()`Có thể đã có người làm @amas127 đã nhận hôm nay. Đang mởtypechecking
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 57/100
-
configuration quansight
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 55/100
-
Version-gated early exits: `from copy import replace` is accepted but `copy.replace` is rejectedĐang mởquansight scoping-control-flow
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
Tất cả issue của facebook/pyrefly
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
tauri-apps/plugins-workspace#3780 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NVIDIA/spark-local-inference#268 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
datafusion-contrib/StreamFusion#653 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug CLI exec session
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày