mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:34:57 +00:00
Rename synthetic annotation => inferred annotation
This commit is contained in:
parent
bf0b191669
commit
730eb90e7b
2 changed files with 18 additions and 18 deletions
|
@ -1202,7 +1202,7 @@ impl Display for DisplayParameter<'_> {
|
||||||
if let Some(name) = self.param.display_name() {
|
if let Some(name) = self.param.display_name() {
|
||||||
f.write_str(&name)?;
|
f.write_str(&name)?;
|
||||||
if let Some(annotated_type) = self.param.annotated_type() {
|
if let Some(annotated_type) = self.param.annotated_type() {
|
||||||
if !self.param.has_synthetic_annotation() {
|
if self.param.should_annotation_be_displayed() {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
": {}",
|
": {}",
|
||||||
|
@ -1229,7 +1229,7 @@ impl Display for DisplayParameter<'_> {
|
||||||
} else if let Some(ty) = self.param.annotated_type() {
|
} else if let Some(ty) = self.param.annotated_type() {
|
||||||
// This case is specifically for the `Callable` signature where name and default value
|
// This case is specifically for the `Callable` signature where name and default value
|
||||||
// cannot be provided.
|
// 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)?;
|
ty.display_with(self.db, self.settings.clone()).fmt(f)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1305,7 +1305,7 @@ impl<'db> Parameters<'db> {
|
||||||
};
|
};
|
||||||
Parameter {
|
Parameter {
|
||||||
annotated_type: Some(implicit_annotation),
|
annotated_type: Some(implicit_annotation),
|
||||||
synthetic_annotation: true,
|
inferred_annotation: true,
|
||||||
kind: ParameterKind::PositionalOrKeyword {
|
kind: ParameterKind::PositionalOrKeyword {
|
||||||
name: arg.parameter.name.id.clone(),
|
name: arg.parameter.name.id.clone(),
|
||||||
default_type: default_type(arg),
|
default_type: default_type(arg),
|
||||||
|
@ -1506,9 +1506,9 @@ pub(crate) struct Parameter<'db> {
|
||||||
/// Annotated type of the parameter.
|
/// Annotated type of the parameter.
|
||||||
annotated_type: Option<Type<'db>>,
|
annotated_type: Option<Type<'db>>,
|
||||||
|
|
||||||
/// If the type of parameter was inferred e.g. the first argument of a method has type
|
/// Does the type of this parameter come from an explicit annotation, or was it inferred from
|
||||||
/// `typing.Self`.
|
/// the context, like `Self` for the `self` parameter of instance methods.
|
||||||
synthetic_annotation: bool,
|
inferred_annotation: bool,
|
||||||
|
|
||||||
kind: ParameterKind<'db>,
|
kind: ParameterKind<'db>,
|
||||||
pub(crate) form: ParameterForm,
|
pub(crate) form: ParameterForm,
|
||||||
|
@ -1518,7 +1518,7 @@ impl<'db> Parameter<'db> {
|
||||||
pub(crate) fn positional_only(name: Option<Name>) -> Self {
|
pub(crate) fn positional_only(name: Option<Name>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
annotated_type: None,
|
annotated_type: None,
|
||||||
synthetic_annotation: false,
|
inferred_annotation: false,
|
||||||
kind: ParameterKind::PositionalOnly {
|
kind: ParameterKind::PositionalOnly {
|
||||||
name,
|
name,
|
||||||
default_type: None,
|
default_type: None,
|
||||||
|
@ -1530,7 +1530,7 @@ impl<'db> Parameter<'db> {
|
||||||
pub(crate) fn positional_or_keyword(name: Name) -> Self {
|
pub(crate) fn positional_or_keyword(name: Name) -> Self {
|
||||||
Self {
|
Self {
|
||||||
annotated_type: None,
|
annotated_type: None,
|
||||||
synthetic_annotation: false,
|
inferred_annotation: false,
|
||||||
kind: ParameterKind::PositionalOrKeyword {
|
kind: ParameterKind::PositionalOrKeyword {
|
||||||
name,
|
name,
|
||||||
default_type: None,
|
default_type: None,
|
||||||
|
@ -1542,7 +1542,7 @@ impl<'db> Parameter<'db> {
|
||||||
pub(crate) fn variadic(name: Name) -> Self {
|
pub(crate) fn variadic(name: Name) -> Self {
|
||||||
Self {
|
Self {
|
||||||
annotated_type: None,
|
annotated_type: None,
|
||||||
synthetic_annotation: false,
|
inferred_annotation: false,
|
||||||
kind: ParameterKind::Variadic { name },
|
kind: ParameterKind::Variadic { name },
|
||||||
form: ParameterForm::Value,
|
form: ParameterForm::Value,
|
||||||
}
|
}
|
||||||
|
@ -1551,7 +1551,7 @@ impl<'db> Parameter<'db> {
|
||||||
pub(crate) fn keyword_only(name: Name) -> Self {
|
pub(crate) fn keyword_only(name: Name) -> Self {
|
||||||
Self {
|
Self {
|
||||||
annotated_type: None,
|
annotated_type: None,
|
||||||
synthetic_annotation: false,
|
inferred_annotation: false,
|
||||||
kind: ParameterKind::KeywordOnly {
|
kind: ParameterKind::KeywordOnly {
|
||||||
name,
|
name,
|
||||||
default_type: None,
|
default_type: None,
|
||||||
|
@ -1563,7 +1563,7 @@ impl<'db> Parameter<'db> {
|
||||||
pub(crate) fn keyword_variadic(name: Name) -> Self {
|
pub(crate) fn keyword_variadic(name: Name) -> Self {
|
||||||
Self {
|
Self {
|
||||||
annotated_type: None,
|
annotated_type: None,
|
||||||
synthetic_annotation: false,
|
inferred_annotation: false,
|
||||||
kind: ParameterKind::KeywordVariadic { name },
|
kind: ParameterKind::KeywordVariadic { name },
|
||||||
form: ParameterForm::Value,
|
form: ParameterForm::Value,
|
||||||
}
|
}
|
||||||
|
@ -1602,7 +1602,7 @@ impl<'db> Parameter<'db> {
|
||||||
.annotated_type
|
.annotated_type
|
||||||
.map(|ty| ty.apply_type_mapping_impl(db, type_mapping, visitor)),
|
.map(|ty| ty.apply_type_mapping_impl(db, type_mapping, visitor)),
|
||||||
kind: self.kind.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,
|
form: self.form,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1618,7 +1618,7 @@ impl<'db> Parameter<'db> {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let Parameter {
|
let Parameter {
|
||||||
annotated_type,
|
annotated_type,
|
||||||
synthetic_annotation,
|
inferred_annotation,
|
||||||
kind,
|
kind,
|
||||||
form,
|
form,
|
||||||
} = self;
|
} = self;
|
||||||
|
@ -1662,7 +1662,7 @@ impl<'db> Parameter<'db> {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
annotated_type: Some(annotated_type),
|
annotated_type: Some(annotated_type),
|
||||||
synthetic_annotation: *synthetic_annotation,
|
inferred_annotation: *inferred_annotation,
|
||||||
kind,
|
kind,
|
||||||
form: *form,
|
form: *form,
|
||||||
}
|
}
|
||||||
|
@ -1685,7 +1685,7 @@ impl<'db> Parameter<'db> {
|
||||||
}),
|
}),
|
||||||
kind,
|
kind,
|
||||||
form: ParameterForm::Value,
|
form: ParameterForm::Value,
|
||||||
synthetic_annotation: false,
|
inferred_annotation: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1740,9 +1740,9 @@ impl<'db> Parameter<'db> {
|
||||||
&self.kind
|
&self.kind
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the type of the parameter was inferred.
|
/// Whether or not the type of this parameter should be displayed.
|
||||||
pub(crate) fn has_synthetic_annotation(&self) -> bool {
|
pub(crate) fn should_annotation_be_displayed(&self) -> bool {
|
||||||
self.synthetic_annotation
|
!self.inferred_annotation
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Name of the parameter (if it has one).
|
/// Name of the parameter (if it has one).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue