Skip to content

Commit 00891ae

Browse files
committed
ty → type
1 parent 9cf9e28 commit 00891ae

File tree

3 files changed

+51
-39
lines changed

3 files changed

+51
-39
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'db> Bindings<'db> {
7474
}
7575

7676
pub(crate) fn callable_type(&self) -> Type<'db> {
77-
self.signatures.ty
77+
self.signatures.callable_type
7878
}
7979

8080
/// Returns the return type of the call. For successful calls, this is the actual return type.
@@ -177,7 +177,7 @@ impl<'db> Bindings<'db> {
177177
node,
178178
format_args!(
179179
"Object of type `{}` is not callable",
180-
self.signatures.ty.display(context.db())
180+
self.signatures.callable_type.display(context.db())
181181
),
182182
);
183183
return;
@@ -361,7 +361,7 @@ impl<'db> CallableBinding<'db> {
361361
node,
362362
format_args!(
363363
"Object of type `{}` is not callable",
364-
self.signature.ty.display(context.db()),
364+
self.signature.callable_type.display(context.db()),
365365
),
366366
);
367367
return;
@@ -373,13 +373,14 @@ impl<'db> CallableBinding<'db> {
373373
node,
374374
format_args!(
375375
"Object of type `{}` is not callable (possibly unbound `__call__` method)",
376-
self.signature.ty.display(context.db()),
376+
self.signature.callable_type.display(context.db()),
377377
),
378378
);
379379
return;
380380
}
381381

382-
let callable_descriptor = CallableDescription::new(context.db(), self.signature.ty);
382+
let callable_descriptor =
383+
CallableDescription::new(context.db(), self.signature.callable_type);
383384
if self.overloads().len() > 1 {
384385
context.report_lint(
385386
&NO_MATCHING_OVERLOAD,
@@ -397,12 +398,12 @@ impl<'db> CallableBinding<'db> {
397398
}
398399

399400
let callable_descriptor =
400-
CallableDescription::new(context.db(), self.signature.signature_ty);
401+
CallableDescription::new(context.db(), self.signature.signature_type);
401402
for overload in self.overloads() {
402403
overload.report_diagnostics(
403404
context,
404405
node,
405-
self.signature.signature_ty,
406+
self.signature.signature_type,
406407
callable_descriptor.as_ref(),
407408
);
408409
}
@@ -586,8 +587,8 @@ pub(crate) struct CallableDescription<'a> {
586587
}
587588

588589
impl<'db> CallableDescription<'db> {
589-
fn new(db: &'db dyn Db, ty: Type<'db>) -> Option<CallableDescription<'db>> {
590-
match ty {
590+
fn new(db: &'db dyn Db, callable_type: Type<'db>) -> Option<CallableDescription<'db>> {
591+
match callable_type {
591592
Type::FunctionLiteral(function) => Some(CallableDescription {
592593
kind: "function",
593594
name: function.name(db),

crates/red_knot_python_semantic/src/types/infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3548,7 +3548,7 @@ impl<'db> TypeInferenceBuilder<'db> {
35483548
for binding in bindings.iter() {
35493549
let Some(known_function) = binding
35503550
.signature
3551-
.ty
3551+
.callable_type
35523552
.into_function_literal()
35533553
.and_then(|function_type| function_type.known(self.db()))
35543554
else {

crates/red_knot_python_semantic/src/types/signatures.rs

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,40 @@ use ruff_python_ast::{self as ast, name::Name};
2121
#[derive(Clone, Debug, PartialEq, Eq, Hash, salsa::Update)]
2222
pub(crate) struct Signatures<'db> {
2323
/// The type that is (hopefully) callable.
24-
pub(crate) ty: Type<'db>,
24+
pub(crate) callable_type: Type<'db>,
2525
/// For an object that's callable via a `__call__` method, the type of that method. For an
2626
/// object that is directly callable, the type of the object.
27-
pub(crate) signature_ty: Type<'db>,
27+
pub(crate) signature_type: Type<'db>,
2828
elements: Vec<CallableSignature<'db>>,
2929
}
3030

3131
impl<'db> Signatures<'db> {
32-
pub(crate) fn not_callable(ty: Type<'db>, signature_ty: Type<'db>) -> Self {
32+
pub(crate) fn not_callable(callable_type: Type<'db>, signature_type: Type<'db>) -> Self {
3333
Self {
34-
ty,
35-
signature_ty,
36-
elements: vec![CallableSignature::not_callable(ty, signature_ty)],
34+
callable_type,
35+
signature_type,
36+
elements: vec![CallableSignature::not_callable(
37+
callable_type,
38+
signature_type,
39+
)],
3740
}
3841
}
3942

4043
pub(crate) fn single(signature: CallableSignature<'db>) -> Self {
4144
Self {
42-
ty: signature.ty,
43-
signature_ty: signature.signature_ty,
45+
callable_type: signature.callable_type,
46+
signature_type: signature.signature_type,
4447
elements: vec![signature],
4548
}
4649
}
4750

4851
/// Creates a new `Signatures` from an iterator of [`Signature`]s. Panics if the iterator is
4952
/// empty.
50-
pub(crate) fn from_union<I>(ty: Type<'db>, signature_ty: Type<'db>, elements: I) -> Self
53+
pub(crate) fn from_union<I>(
54+
callable_type: Type<'db>,
55+
signature_type: Type<'db>,
56+
elements: I,
57+
) -> Self
5158
where
5259
I: IntoIterator<Item = &'db Signatures<'db>>,
5360
{
@@ -56,8 +63,8 @@ impl<'db> Signatures<'db> {
5663
.flat_map(|s| s.elements.iter().cloned())
5764
.collect();
5865
Self {
59-
ty,
60-
signature_ty,
66+
callable_type,
67+
signature_type,
6168
elements,
6269
}
6370
}
@@ -85,11 +92,11 @@ impl<'db> Signatures<'db> {
8592
#[derive(Clone, Debug, PartialEq, Eq, Hash, salsa::Update)]
8693
pub(crate) struct CallableSignature<'db> {
8794
/// The type that is (hopefully) callable.
88-
pub(crate) ty: Type<'db>,
95+
pub(crate) callable_type: Type<'db>,
8996

9097
/// For an object that's callable via a `__call__` method, the type of that method. For an
9198
/// object that is directly callable, the type of the object.
92-
pub(crate) signature_ty: Type<'db>,
99+
pub(crate) signature_type: Type<'db>,
93100

94101
/// If this is a callable object (i.e. called via a `__call__` method), the boundness of
95102
/// that call method.
@@ -102,62 +109,66 @@ pub(crate) struct CallableSignature<'db> {
102109
}
103110

104111
impl<'db> CallableSignature<'db> {
105-
pub(crate) fn not_callable(ty: Type<'db>, signature_ty: Type<'db>) -> Self {
112+
pub(crate) fn not_callable(callable_type: Type<'db>, signature_type: Type<'db>) -> Self {
106113
Self {
107-
ty,
108-
signature_ty,
114+
callable_type,
115+
signature_type,
109116
dunder_call_boundness: None,
110117
bound_type: None,
111118
overloads: vec![],
112119
}
113120
}
114121

115122
pub(crate) fn single(
116-
ty: Type<'db>,
117-
signature_ty: Type<'db>,
123+
callable_type: Type<'db>,
124+
signature_type: Type<'db>,
118125
signature: Signature<'db>,
119126
) -> Self {
120127
Self {
121-
ty,
122-
signature_ty,
128+
callable_type,
129+
signature_type,
123130
dunder_call_boundness: None,
124131
bound_type: None,
125132
overloads: vec![signature],
126133
}
127134
}
128135

129136
/// Creates a new `CallableSignature` from a non-empty iterator of [`Signature`]s.
130-
pub(crate) fn from_overloads<I>(ty: Type<'db>, signature_ty: Type<'db>, overloads: I) -> Self
137+
pub(crate) fn from_overloads<I>(
138+
callable_type: Type<'db>,
139+
signature_type: Type<'db>,
140+
overloads: I,
141+
) -> Self
131142
where
132143
I: IntoIterator<Item = Signature<'db>>,
133144
{
134145
Self {
135-
ty,
136-
signature_ty,
146+
callable_type,
147+
signature_type,
137148
dunder_call_boundness: None,
138149
bound_type: None,
139150
overloads: overloads.into_iter().collect(),
140151
}
141152
}
142153

143154
/// Return a signature for a dynamic callable
144-
pub(crate) fn dynamic(ty: Type<'db>) -> Self {
155+
pub(crate) fn dynamic(callable_type: Type<'db>) -> Self {
145156
let signature = Signature {
146157
parameters: Parameters::gradual_form(),
147-
return_ty: Some(ty),
158+
return_ty: Some(callable_type),
148159
};
149-
Self::single(ty, ty, signature)
160+
Self::single(callable_type, callable_type, signature)
150161
}
151162

152163
/// Return a todo signature: (*args: Todo, **kwargs: Todo) -> Todo
153164
#[allow(unused_variables)] // 'reason' only unused in debug builds
154165
pub(crate) fn todo(reason: &'static str) -> Self {
155-
let ty = todo_type!(reason);
166+
let callable_type = todo_type!(reason);
156167
let signature = Signature {
157168
parameters: Parameters::todo(),
158-
return_ty: Some(ty),
169+
return_ty: Some(callable_type),
159170
};
160-
Self::single(ty, ty, signature)
171+
Self::single(callable_type, callable_type, signature)
161172
}
162173

163174
/// Returns the [`Signature`] if this is a non-overloaded callable, [None] otherwise.

0 commit comments

Comments
 (0)