mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 06:42:02 +00:00
[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:
parent
adc4216afb
commit
4f74db5630
7 changed files with 241 additions and 63 deletions
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue