[red-knot] Improve Symbol API for callable types (#14137)

## Summary

- Get rid of `Symbol::unwrap_or` (unclear semantics, not needed anymore)
- Introduce `Type::call_dunder`
- Emit new diagnostic for possibly-unbound `__iter__` methods
- Better diagnostics for callables with possibly-unbound /
possibly-non-callable `__call__` methods

part of: #14022 

closes #14016

## Test Plan

- Updated test for iterables with possibly-unbound `__iter__` methods.
- New tests for callables
This commit is contained in:
David Peter 2024-11-07 19:58:31 +01:00 committed by GitHub
parent adc4216afb
commit 4f74db5630
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 241 additions and 63 deletions

View file

@ -3,7 +3,7 @@ use crate::{
Db,
};
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Boundness {
Bound,
MayBeUnbound,
@ -44,17 +44,13 @@ impl<'db> Symbol<'db> {
}
}
pub(crate) fn unwrap_or(&self, other: Type<'db>) -> Type<'db> {
pub(crate) fn unwrap_or_unknown(&self) -> Type<'db> {
match self {
Symbol::Type(ty, _) => *ty,
Symbol::Unbound => other,
Symbol::Unbound => Type::Unknown,
}
}
pub(crate) fn unwrap_or_unknown(&self) -> Type<'db> {
self.unwrap_or(Type::Unknown)
}
pub(crate) fn as_type(&self) -> Option<Type<'db>> {
match self {
Symbol::Type(ty, _) => Some(*ty),