[ty] Validate constructor arguments when a class is used as a decorator#22377
[ty] Validate constructor arguments when a class is used as a decorator#22377charliermarsh merged 4 commits intomainfrom
Conversation
Typing conformance resultsNo changes detected ✅ |
|
|
this looks like it might conflict quite badly with #22124, though I have no idea how close that PR is to landing |
aa17527 to
10d4e56
Compare
#22124 is currently ready for review, but with a few questions in need of some guidance, so I would not say it's going to land very soon |
AlexWaygood
left a comment
There was a problem hiding this comment.
This isn't a full review but it looks like I got halfway through reviewing last week, so here's a partial review
There was a problem hiding this comment.
I did not review the tests very thoroughly since @AlexWaygood already did.
On the code side, I have a mild concern that we're duplicating the "class constructors should not use try_call" logic in so many places, but that fact isn't introduced by this PR, so I don't consider that a blocker here. If we don't have an open issue for that (making try_call work for all call sites and callables) we should open one.
| Err(err) => { | ||
| err.report_diagnostic(&self.context, decorator_ty, decorator_node.into()); | ||
| err.return_type() | ||
| } |
There was a problem hiding this comment.
This error arm is slightly different than the one below. Do they produce different diagnostics? If so, is that on purpose? If we could consolidate these two arms to be identical, then we could collapse this down overall to something like
let call_arguments = CallArguments::positional([decorated_ty]);
let call_result = if use_constructor_call {
decorator_ty.try_call_constructor(
self.db(),
|_| call_arguments,
TypeContext::default(),
)
} else {
decorator_ty
.try_call(self.db(), &call_arguments)
.map(|bindings| bindings.return_type(self.db()))
};
match call_result {
Ok(return_ty) => ...
Err(err) => ...
}There was a problem hiding this comment.
I think the error types are slightly different -- ConstructorCallError vs. CallError -- but I tried to unify more.
a304a6f to
e527848
Compare
e527848 to
9408474
Compare
|
(Reviewing ecosystem results...) |
|
I believe the WerkZeug diagnostics are true positives because we now "see" the cached property decorator. |
Summary
If a class is used as a decorator, we now use the class constructor.
Closes astral-sh/ty#2232.