diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index f9835e7db8..91ac13e3d5 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -412,14 +412,6 @@ impl<'db> PropertyInstanceType<'db> { self.setter(db).map(|ty| ty.materialize(db, variance)), ) } - - fn any_over_type(self, db: &'db dyn Db, type_fn: &dyn Fn(Type<'db>) -> bool) -> bool { - self.getter(db) - .is_some_and(|ty| ty.any_over_type(db, type_fn)) - || self - .setter(db) - .is_some_and(|ty| ty.any_over_type(db, type_fn)) - } } bitflags! { @@ -753,110 +745,6 @@ impl<'db> Type<'db> { } } - /// Return `true` if `self`, or any of the types contained in `self`, match the closure passed in. - pub fn any_over_type(self, db: &'db dyn Db, type_fn: &dyn Fn(Type<'db>) -> bool) -> bool { - if type_fn(self) { - return true; - } - - match self { - Self::AlwaysFalsy - | Self::AlwaysTruthy - | Self::Never - | Self::BooleanLiteral(_) - | Self::BytesLiteral(_) - | Self::ModuleLiteral(_) - | Self::FunctionLiteral(_) - | Self::ClassLiteral(_) - | Self::SpecialForm(_) - | Self::KnownInstance(_) - | Self::StringLiteral(_) - | Self::IntLiteral(_) - | Self::LiteralString - | Self::Dynamic(_) - | Self::BoundMethod(_) - | Self::WrapperDescriptor(_) - | Self::MethodWrapper(_) - | Self::DataclassDecorator(_) - | Self::DataclassTransformer(_) => false, - - Self::GenericAlias(generic) => generic - .specialization(db) - .types(db) - .iter() - .copied() - .any(|ty| ty.any_over_type(db, type_fn)), - - Self::Callable(callable) => { - let signatures = callable.signatures(db); - signatures.iter().any(|signature| { - signature.parameters().iter().any(|param| { - param - .annotated_type() - .is_some_and(|ty| ty.any_over_type(db, type_fn)) - }) || signature - .return_ty - .is_some_and(|ty| ty.any_over_type(db, type_fn)) - }) - } - - Self::SubclassOf(subclass_of) => { - Type::from(subclass_of.subclass_of()).any_over_type(db, type_fn) - } - - Self::TypeVar(typevar) => match typevar.bound_or_constraints(db) { - None => false, - Some(TypeVarBoundOrConstraints::UpperBound(bound)) => { - bound.any_over_type(db, type_fn) - } - Some(TypeVarBoundOrConstraints::Constraints(constraints)) => constraints - .elements(db) - .iter() - .any(|constraint| constraint.any_over_type(db, type_fn)), - }, - - Self::BoundSuper(bound_super) => { - Type::from(bound_super.pivot_class(db)).any_over_type(db, type_fn) - || Type::from(bound_super.owner(db)).any_over_type(db, type_fn) - } - - Self::Tuple(tuple) => tuple - .tuple(db) - .all_elements() - .any(|ty| ty.any_over_type(db, type_fn)), - - Self::Union(union) => union - .elements(db) - .iter() - .any(|ty| ty.any_over_type(db, type_fn)), - - Self::Intersection(intersection) => { - intersection - .positive(db) - .iter() - .any(|ty| ty.any_over_type(db, type_fn)) - || intersection - .negative(db) - .iter() - .any(|ty| ty.any_over_type(db, type_fn)) - } - - Self::ProtocolInstance(protocol) => protocol.any_over_type(db, type_fn), - Self::PropertyInstance(property) => property.any_over_type(db, type_fn), - - Self::NominalInstance(instance) => match instance.class { - ClassType::NonGeneric(_) => false, - ClassType::Generic(generic) => generic - .specialization(db) - .types(db) - .iter() - .any(|ty| ty.any_over_type(db, type_fn)), - }, - - Self::TypeIs(type_is) => type_is.return_type(db).any_over_type(db, type_fn), - } - } - pub const fn into_class_literal(self) -> Option> { match self { Type::ClassLiteral(class_type) => Some(class_type), diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index 7297e32996..a7c6b4e2d9 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -1145,11 +1145,11 @@ impl KnownFunction { let [Some(casted_type), Some(source_type)] = parameter_types else { return None; }; - let contains_unknown_or_todo = + let is_unknown_or_todo = |ty| matches!(ty, Type::Dynamic(dynamic) if dynamic != DynamicType::Any); if source_type.is_equivalent_to(db, *casted_type) - && !casted_type.any_over_type(db, &|ty| contains_unknown_or_todo(ty)) - && !source_type.any_over_type(db, &|ty| contains_unknown_or_todo(ty)) + && !is_unknown_or_todo(*casted_type) + && !is_unknown_or_todo(*source_type) { let builder = context.report_lint(&REDUNDANT_CAST, call_expression)?; builder.into_diagnostic(format_args!( diff --git a/crates/ty_python_semantic/src/types/instance.rs b/crates/ty_python_semantic/src/types/instance.rs index f5038da6fc..c9134b404a 100644 --- a/crates/ty_python_semantic/src/types/instance.rs +++ b/crates/ty_python_semantic/src/types/instance.rs @@ -229,15 +229,6 @@ impl<'db> ProtocolInstanceType<'db> { } } - /// Return `true` if the types of any of the members match the closure passed in. - pub(super) fn any_over_type( - self, - db: &'db dyn Db, - type_fn: &dyn Fn(Type<'db>) -> bool, - ) -> bool { - self.inner.interface(db).any_over_type(db, type_fn) - } - /// Return `true` if this protocol type has the given type relation to the protocol `other`. /// /// TODO: consider the types of the members as well as their existence diff --git a/crates/ty_python_semantic/src/types/protocol_class.rs b/crates/ty_python_semantic/src/types/protocol_class.rs index 5ac8324328..c1ef5fca20 100644 --- a/crates/ty_python_semantic/src/types/protocol_class.rs +++ b/crates/ty_python_semantic/src/types/protocol_class.rs @@ -152,16 +152,6 @@ impl<'db> ProtocolInterface<'db> { .all(|member_name| other.inner(db).contains_key(member_name)) } - /// Return `true` if the types of any of the members match the closure passed in. - pub(super) fn any_over_type( - self, - db: &'db dyn Db, - type_fn: &dyn Fn(Type<'db>) -> bool, - ) -> bool { - self.members(db) - .any(|member| member.any_over_type(db, type_fn)) - } - pub(super) fn normalized_impl(self, db: &'db dyn Db, visitor: &mut TypeVisitor<'db>) -> Self { Self::new( db, @@ -371,14 +361,6 @@ impl<'a, 'db> ProtocolMember<'a, 'db> { } } } - - fn any_over_type(&self, db: &'db dyn Db, type_fn: &dyn Fn(Type<'db>) -> bool) -> bool { - match &self.kind { - ProtocolMemberKind::Method(callable) => callable.any_over_type(db, type_fn), - ProtocolMemberKind::Property(property) => property.any_over_type(db, type_fn), - ProtocolMemberKind::Other(ty) => ty.any_over_type(db, type_fn), - } - } } /// Returns `true` if a declaration or binding to a given name in a protocol class body