Skip to content

Commit 35f9adb

Browse files
fix name load usage also
1 parent 728d3ec commit 35f9adb

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

crates/ty_python_semantic/resources/mdtest/dataclass_transform.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,10 @@ class D1:
281281
class D2:
282282
x: str
283283

284-
# TODO: these should not be errors
285-
D1("a") # error: [too-many-positional-arguments]
284+
D1("a")
286285
D2("a")
287286

288-
# TODO: these should be invalid-argument-type errors
289-
D1(1.2) # error: [too-many-positional-arguments]
287+
D1(1.2) # error: [invalid-argument-type]
290288
D2(1.2) # error: [invalid-argument-type]
291289
```
292290

crates/ty_python_semantic/src/types/call/bind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ impl<'db> Bindings<'db> {
811811
.overloads
812812
.iter()
813813
.for_each(&mut handle_dataclass_transformer_params);
814-
};
814+
}
815815

816816
handle_dataclass_transformer_params(&function_type);
817817
}

crates/ty_python_semantic/src/types/infer.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,17 @@ impl<'db> TypeInferenceBuilder<'db> {
20992099
}
21002100

21012101
if let Type::FunctionLiteral(f) = decorator_ty {
2102+
// We do not yet detect or flag `@dataclass_transformer` applied to more than one
2103+
// overload, or an overload and the implementation both. Nevertheless, this is not
2104+
// allowed. We do not try to treat the offenders intelligently -- just use the
2105+
// params of the last seen usage of `@dataclass_transformer`
2106+
if let Some(overloaded) = f.to_overloaded(self.db()) {
2107+
overloaded.overloads.iter().for_each(|overload| {
2108+
if let Some(params) = overload.dataclass_transformer_params(self.db()) {
2109+
dataclass_params = Some(params.into());
2110+
}
2111+
});
2112+
}
21022113
if let Some(params) = f.dataclass_transformer_params(self.db()) {
21032114
dataclass_params = Some(params.into());
21042115
continue;

0 commit comments

Comments
 (0)