diff --git a/crates/ty_python_semantic/src/types/display.rs b/crates/ty_python_semantic/src/types/display.rs index 553ae9d901..b25cabc9ec 100644 --- a/crates/ty_python_semantic/src/types/display.rs +++ b/crates/ty_python_semantic/src/types/display.rs @@ -1202,7 +1202,7 @@ impl Display for DisplayParameter<'_> { if let Some(name) = self.param.display_name() { f.write_str(&name)?; if let Some(annotated_type) = self.param.annotated_type() { - if !self.param.has_synthetic_annotation() { + if self.param.should_annotation_be_displayed() { write!( f, ": {}", @@ -1229,7 +1229,7 @@ impl Display for DisplayParameter<'_> { } else if let Some(ty) = self.param.annotated_type() { // This case is specifically for the `Callable` signature where name and default value // cannot be provided. - if !self.param.has_synthetic_annotation() { + if self.param.should_annotation_be_displayed() { ty.display_with(self.db, self.settings.clone()).fmt(f)?; } } diff --git a/crates/ty_python_semantic/src/types/signatures.rs b/crates/ty_python_semantic/src/types/signatures.rs index bce0eed3f6..0e282395d7 100644 --- a/crates/ty_python_semantic/src/types/signatures.rs +++ b/crates/ty_python_semantic/src/types/signatures.rs @@ -1305,7 +1305,7 @@ impl<'db> Parameters<'db> { }; Parameter { annotated_type: Some(implicit_annotation), - synthetic_annotation: true, + inferred_annotation: true, kind: ParameterKind::PositionalOrKeyword { name: arg.parameter.name.id.clone(), default_type: default_type(arg), @@ -1506,9 +1506,9 @@ pub(crate) struct Parameter<'db> { /// Annotated type of the parameter. annotated_type: Option>, - /// If the type of parameter was inferred e.g. the first argument of a method has type - /// `typing.Self`. - synthetic_annotation: bool, + /// Does the type of this parameter come from an explicit annotation, or was it inferred from + /// the context, like `Self` for the `self` parameter of instance methods. + inferred_annotation: bool, kind: ParameterKind<'db>, pub(crate) form: ParameterForm, @@ -1518,7 +1518,7 @@ impl<'db> Parameter<'db> { pub(crate) fn positional_only(name: Option) -> Self { Self { annotated_type: None, - synthetic_annotation: false, + inferred_annotation: false, kind: ParameterKind::PositionalOnly { name, default_type: None, @@ -1530,7 +1530,7 @@ impl<'db> Parameter<'db> { pub(crate) fn positional_or_keyword(name: Name) -> Self { Self { annotated_type: None, - synthetic_annotation: false, + inferred_annotation: false, kind: ParameterKind::PositionalOrKeyword { name, default_type: None, @@ -1542,7 +1542,7 @@ impl<'db> Parameter<'db> { pub(crate) fn variadic(name: Name) -> Self { Self { annotated_type: None, - synthetic_annotation: false, + inferred_annotation: false, kind: ParameterKind::Variadic { name }, form: ParameterForm::Value, } @@ -1551,7 +1551,7 @@ impl<'db> Parameter<'db> { pub(crate) fn keyword_only(name: Name) -> Self { Self { annotated_type: None, - synthetic_annotation: false, + inferred_annotation: false, kind: ParameterKind::KeywordOnly { name, default_type: None, @@ -1563,7 +1563,7 @@ impl<'db> Parameter<'db> { pub(crate) fn keyword_variadic(name: Name) -> Self { Self { annotated_type: None, - synthetic_annotation: false, + inferred_annotation: false, kind: ParameterKind::KeywordVariadic { name }, form: ParameterForm::Value, } @@ -1602,7 +1602,7 @@ impl<'db> Parameter<'db> { .annotated_type .map(|ty| ty.apply_type_mapping_impl(db, type_mapping, visitor)), kind: self.kind.apply_type_mapping_impl(db, type_mapping, visitor), - synthetic_annotation: self.synthetic_annotation, + inferred_annotation: self.inferred_annotation, form: self.form, } } @@ -1618,7 +1618,7 @@ impl<'db> Parameter<'db> { ) -> Self { let Parameter { annotated_type, - synthetic_annotation, + inferred_annotation, kind, form, } = self; @@ -1662,7 +1662,7 @@ impl<'db> Parameter<'db> { Self { annotated_type: Some(annotated_type), - synthetic_annotation: *synthetic_annotation, + inferred_annotation: *inferred_annotation, kind, form: *form, } @@ -1685,7 +1685,7 @@ impl<'db> Parameter<'db> { }), kind, form: ParameterForm::Value, - synthetic_annotation: false, + inferred_annotation: false, } } @@ -1740,9 +1740,9 @@ impl<'db> Parameter<'db> { &self.kind } - /// Whether the type of the parameter was inferred. - pub(crate) fn has_synthetic_annotation(&self) -> bool { - self.synthetic_annotation + /// Whether or not the type of this parameter should be displayed. + pub(crate) fn should_annotation_be_displayed(&self) -> bool { + !self.inferred_annotation } /// Name of the parameter (if it has one).