[ty] Rename set_invalid_syntax to set_invalid_type_annotation (#22140)
This commit is contained in:
@@ -215,7 +215,7 @@ impl<'a, 'b, 'db> TypeWriter<'a, 'b, 'db> {
|
||||
self.with_detail(TypeDetail::Type(ty))
|
||||
}
|
||||
|
||||
fn set_invalid_syntax(&mut self) {
|
||||
fn set_invalid_type_annotation(&mut self) {
|
||||
match self {
|
||||
TypeWriter::Formatter(_) => {}
|
||||
TypeWriter::Details(details) => details.is_valid_syntax = false,
|
||||
@@ -571,7 +571,7 @@ impl<'db> FmtDetailed<'db> for ClassDisplay<'db> {
|
||||
let line_index = line_index(self.db, file);
|
||||
let class_offset = self.class.header_range(self.db).start();
|
||||
let line_number = line_index.line_index(class_offset);
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
write!(f, " @ {path}:{line_number}")?;
|
||||
}
|
||||
Ok(())
|
||||
@@ -604,7 +604,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
match self.ty {
|
||||
Type::Dynamic(dynamic) => {
|
||||
if dynamic.is_todo() {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
}
|
||||
write!(f.with_type(self.ty), "{dynamic}")
|
||||
}
|
||||
@@ -637,7 +637,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
.fmt_detailed(f),
|
||||
},
|
||||
Protocol::Synthesized(synthetic) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_char('<')?;
|
||||
f.with_type(Type::SpecialForm(SpecialFormType::Protocol))
|
||||
.write_str("Protocol")?;
|
||||
@@ -657,7 +657,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
},
|
||||
Type::PropertyInstance(_) => f.with_type(self.ty).write_str("property"),
|
||||
Type::ModuleLiteral(module) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_char('<')?;
|
||||
f.with_type(KnownClass::ModuleType.to_class_literal(self.db))
|
||||
.write_str("module")?;
|
||||
@@ -667,7 +667,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
f.write_str("'>")
|
||||
}
|
||||
Type::ClassLiteral(class) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
let mut f = f.with_type(self.ty);
|
||||
f.write_str("<class '")?;
|
||||
class
|
||||
@@ -676,7 +676,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
f.write_str("'>")
|
||||
}
|
||||
Type::GenericAlias(generic) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
let mut f = f.with_type(self.ty);
|
||||
f.write_str("<class '")?;
|
||||
generic
|
||||
@@ -711,7 +711,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
f.write_char(']')
|
||||
}
|
||||
SubclassOfInner::TypeVar(bound_typevar) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.with_type(KnownClass::Type.to_class_literal(self.db))
|
||||
.write_str("type")?;
|
||||
f.write_char('[')?;
|
||||
@@ -724,7 +724,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
}
|
||||
},
|
||||
Type::SpecialForm(special_form) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
write!(f.with_type(self.ty), "<special-form '{special_form}'>")
|
||||
}
|
||||
Type::KnownInstance(known_instance) => known_instance
|
||||
@@ -748,7 +748,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
db: self.db,
|
||||
settings: self.settings.clone(),
|
||||
};
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("bound method ")?;
|
||||
self_ty
|
||||
.display_with(self.db, self.settings.singleline())
|
||||
@@ -787,7 +787,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
}
|
||||
}
|
||||
Type::KnownBoundMethod(method_type) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
let (cls, member_name, cls_name, ty, ty_name) = match method_type {
|
||||
KnownBoundMethodType::FunctionTypeDunderGet(function) => (
|
||||
KnownClass::FunctionType,
|
||||
@@ -876,7 +876,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
}
|
||||
}
|
||||
Type::WrapperDescriptor(kind) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
let (method, object, cls) = match kind {
|
||||
WrapperDescriptorKind::FunctionTypeDunderGet => {
|
||||
("__get__", "function", KnownClass::FunctionType)
|
||||
@@ -899,11 +899,11 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
f.write_str("' objects>")
|
||||
}
|
||||
Type::DataclassDecorator(_) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("<decorator produced by dataclass-like function>")
|
||||
}
|
||||
Type::DataclassTransformer(_) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("<decorator produced by typing.dataclass_transform>")
|
||||
}
|
||||
Type::Union(union) => union
|
||||
@@ -947,13 +947,13 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
write!(f, ".{}", enum_literal.name(self.db))
|
||||
}
|
||||
Type::TypeVar(bound_typevar) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
write!(f, "{}", bound_typevar.identity(self.db).display(self.db))
|
||||
}
|
||||
Type::AlwaysTruthy => f.with_type(self.ty).write_str("AlwaysTruthy"),
|
||||
Type::AlwaysFalsy => f.with_type(self.ty).write_str("AlwaysFalsy"),
|
||||
Type::BoundSuper(bound_super) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("<super: ")?;
|
||||
Type::from(bound_super.pivot_class(self.db))
|
||||
.display_with(self.db, self.settings.singleline())
|
||||
@@ -973,7 +973,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
.display_with(self.db, self.settings.singleline())
|
||||
.fmt_detailed(f)?;
|
||||
if let Some(name) = type_is.place_name(self.db) {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str(" @ ")?;
|
||||
f.write_str(&name)?;
|
||||
}
|
||||
@@ -985,7 +985,7 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
|
||||
.display_with(self.db, self.settings.clone())
|
||||
.fmt_detailed(f),
|
||||
Type::TypedDict(TypedDictType::Synthesized(synthesized)) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_char('<')?;
|
||||
f.with_type(Type::SpecialForm(SpecialFormType::TypedDict))
|
||||
.write_str("TypedDict")?;
|
||||
@@ -1169,7 +1169,7 @@ impl<'db> FmtDetailed<'db> for DisplayOverloadLiteral<'db> {
|
||||
settings: self.settings.clone(),
|
||||
};
|
||||
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("def ")?;
|
||||
write!(f, "{}", self.literal.name(self.db))?;
|
||||
type_parameters.fmt_detailed(f)?;
|
||||
@@ -1216,7 +1216,7 @@ impl<'db> FmtDetailed<'db> for DisplayFunctionType<'db> {
|
||||
db: self.db,
|
||||
settings: self.settings.clone(),
|
||||
};
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("def ")?;
|
||||
write!(f, "{}", self.ty.name(self.db))?;
|
||||
type_parameters.fmt_detailed(f)?;
|
||||
@@ -1397,7 +1397,7 @@ impl<'db> DisplayGenericContext<'_, 'db> {
|
||||
if idx > 0 {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
let typevar = bound_typevar.typevar(self.db);
|
||||
if typevar.is_paramspec(self.db) {
|
||||
f.write_str("**")?;
|
||||
@@ -1418,7 +1418,7 @@ impl<'db> DisplayGenericContext<'_, 'db> {
|
||||
if idx > 0 {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
write!(
|
||||
f.with_type(Type::TypeVar(bound_typevar)),
|
||||
"{}",
|
||||
@@ -1513,7 +1513,7 @@ impl<'db> DisplaySpecialization<'db> {
|
||||
if idx > 0 {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
write!(f, "{}", bound_typevar.identity(self.db).display(self.db))?;
|
||||
f.write_str(" = ")?;
|
||||
ty.display_with(self.db, self.settings.clone())
|
||||
@@ -1674,7 +1674,7 @@ impl<'db> FmtDetailed<'db> for DisplaySignature<'_, 'db> {
|
||||
fn fmt_detailed(&self, f: &mut TypeWriter<'_, '_, 'db>) -> fmt::Result {
|
||||
// Immediately write a marker signaling we're starting a signature
|
||||
let _ = f.with_detail(TypeDetail::SignatureStart);
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
// When we exit this function, write a marker signaling we're ending a signature
|
||||
let mut f = f.with_detail(TypeDetail::SignatureEnd);
|
||||
|
||||
@@ -1951,7 +1951,7 @@ impl<'db> FmtDetailed<'db> for DisplayOmitted {
|
||||
} else {
|
||||
self.plural
|
||||
};
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
write!(f, "... omitted {} {}", self.count, noun)
|
||||
}
|
||||
}
|
||||
@@ -2166,7 +2166,7 @@ impl<'db> FmtDetailed<'db> for DisplayIntersectionType<'_, 'db> {
|
||||
}),
|
||||
);
|
||||
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.join(" & ").entries(tys).finish()
|
||||
}
|
||||
}
|
||||
@@ -2219,7 +2219,7 @@ struct DisplayMaybeParenthesizedType<'db> {
|
||||
impl<'db> FmtDetailed<'db> for DisplayMaybeParenthesizedType<'db> {
|
||||
fn fmt_detailed(&self, f: &mut TypeWriter<'_, '_, 'db>) -> fmt::Result {
|
||||
let write_parentheses = |f: &mut TypeWriter<'_, '_, 'db>| {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_char('(')?;
|
||||
self.ty
|
||||
.display_with(self.db, self.settings.clone())
|
||||
@@ -2386,7 +2386,7 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||
let ty = Type::KnownInstance(self.known_instance);
|
||||
match self.known_instance {
|
||||
KnownInstanceType::SubscriptedProtocol(generic_context) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("<special-form '")?;
|
||||
f.with_type(Type::SpecialForm(SpecialFormType::Protocol))
|
||||
.write_str("typing.Protocol")?;
|
||||
@@ -2394,7 +2394,7 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||
f.write_str("'>")
|
||||
}
|
||||
KnownInstanceType::SubscriptedGeneric(generic_context) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("<special-form '")?;
|
||||
f.with_type(Type::SpecialForm(SpecialFormType::Generic))
|
||||
.write_str("typing.Generic")?;
|
||||
@@ -2403,7 +2403,7 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||
}
|
||||
KnownInstanceType::TypeAliasType(alias) => {
|
||||
if let Some(specialization) = alias.specialization(self.db) {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("<type alias '")?;
|
||||
f.with_type(ty).write_str(alias.name(self.db))?;
|
||||
specialization
|
||||
@@ -2447,7 +2447,7 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||
write!(f, "{}", specialization.display_full(self.db))
|
||||
}
|
||||
KnownInstanceType::UnionType(union) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_char('<')?;
|
||||
f.with_type(KnownClass::UnionType.to_class_literal(self.db))
|
||||
.write_str("types.UnionType")?;
|
||||
@@ -2460,13 +2460,13 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||
f.write_char('>')
|
||||
}
|
||||
KnownInstanceType::Literal(inner) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("<special-form '")?;
|
||||
inner.inner(self.db).display(self.db).fmt_detailed(f)?;
|
||||
f.write_str("'>")
|
||||
}
|
||||
KnownInstanceType::Annotated(inner) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("<special-form '")?;
|
||||
f.with_type(Type::SpecialForm(SpecialFormType::Annotated))
|
||||
.write_str("typing.Annotated")?;
|
||||
@@ -2475,7 +2475,7 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||
f.write_str(", <metadata>]'>")
|
||||
}
|
||||
KnownInstanceType::Callable(callable) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_char('<')?;
|
||||
f.with_type(Type::SpecialForm(SpecialFormType::Callable))
|
||||
.write_str("typing.Callable")?;
|
||||
@@ -2484,7 +2484,7 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||
f.write_str("'>")
|
||||
}
|
||||
KnownInstanceType::TypeGenericAlias(inner) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_str("<special-form '")?;
|
||||
f.with_type(KnownClass::Type.to_class_literal(self.db))
|
||||
.write_str("type")?;
|
||||
@@ -2496,7 +2496,7 @@ impl<'db> FmtDetailed<'db> for DisplayKnownInstanceRepr<'db> {
|
||||
.with_type(KnownClass::Str.to_class_literal(self.db))
|
||||
.write_str("str"),
|
||||
KnownInstanceType::NewType(declaration) => {
|
||||
f.set_invalid_syntax();
|
||||
f.set_invalid_type_annotation();
|
||||
f.write_char('<')?;
|
||||
f.with_type(KnownClass::NewType.to_class_literal(self.db))
|
||||
.write_str("NewType")?;
|
||||
|
||||
Reference in New Issue
Block a user