-
Notifications
You must be signed in to change notification settings - Fork 216
Closed
astral-sh/ruff
#18115Labels
bugSomething isn't workingSomething isn't workingdataclassesIssues relating to dataclasses and dataclass_transformIssues relating to dataclasses and dataclass_transform
Description
Summary
The type checker incorrectly reports a "no-matching-overload" error for dataclasses.asdict when its result is used for keyword argument unpacking (**asdict(params)) during the instantiation of a class, even when the params object is a valid dataclass instance and asdict is imported correctly.
Steps to Reproduce
An MVE:
import logging
from dataclasses import asdict, dataclass
class DummyModel:
def __init__(self, model_path: str, verbose: bool = False, **kwargs):
self.model_path = model_path
self.verbose = verbose
self.other_params = kwargs
@dataclass
class ModelParams:
max_tokens: int = 10
n_gpu_layers: int = -1
temperature: float = 0.0
def init_dummy_model(model_path: str, **kwargs):
params = ModelParams(**kwargs)
try:
# The following line triggers the "no-matching-overload" error
# when checked with ty/Ruff
model_instance = DummyModel(model_path=model_path, verbose=True, **asdict(params))
print("Model initialized successfully.")
except Exception as e:
print(f"Error during model initialization: {e}")
raise
if __name__ == "__main__":
dummy_path = "dummy_model.gguf"
with open(dummy_path, "w") as f:
f.write("This is a dummy model file.")
init_dummy_model(model_path=dummy_path, max_tokens=100, temperature=0.7)Expected Behavior
The type checker should not report any errors, as asdict(params) returns a dict[str, Any], which is valid for keyword argument unpacking (**) when instantiating DummyModel (or LlamaCpp in the original context). The DummyModel (and LlamaCpp) is designed to accept arbitrary keyword arguments.
Actual Behavior
The type checker reports a no-matching-overload error for the asdict(params) call on the line where DummyModel is instantiated:
Version
ty 0.0.1-alpha.2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingdataclassesIssues relating to dataclasses and dataclass_transformIssues relating to dataclasses and dataclass_transform