remove SupportsIndex/Sized workarounds
This commit is contained in:
@@ -7,7 +7,7 @@ Builtin symbols can be explicitly imported:
|
||||
```py
|
||||
import builtins
|
||||
|
||||
reveal_type(builtins.chr) # revealed: def chr(i: int | SupportsIndex, /) -> str
|
||||
reveal_type(builtins.chr) # revealed: def chr(i: SupportsIndex, /) -> str
|
||||
```
|
||||
|
||||
## Implicit use of builtin
|
||||
@@ -15,7 +15,7 @@ reveal_type(builtins.chr) # revealed: def chr(i: int | SupportsIndex, /) -> str
|
||||
Or used implicitly:
|
||||
|
||||
```py
|
||||
reveal_type(chr) # revealed: def chr(i: int | SupportsIndex, /) -> str
|
||||
reveal_type(chr) # revealed: def chr(i: SupportsIndex, /) -> str
|
||||
reveal_type(str) # revealed: Literal[str]
|
||||
```
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ if returns_bool():
|
||||
chr: int = 1
|
||||
|
||||
def f():
|
||||
reveal_type(chr) # revealed: int | (def chr(i: int | SupportsIndex, /) -> str)
|
||||
reveal_type(chr) # revealed: int | (def chr(i: SupportsIndex, /) -> str)
|
||||
```
|
||||
|
||||
## Conditionally global or builtin, with annotation
|
||||
@@ -28,5 +28,5 @@ if returns_bool():
|
||||
chr: int = 1
|
||||
|
||||
def f():
|
||||
reveal_type(chr) # revealed: int | (def chr(i: int | SupportsIndex, /) -> str)
|
||||
reveal_type(chr) # revealed: int | (def chr(i: SupportsIndex, /) -> str)
|
||||
```
|
||||
|
||||
@@ -1453,38 +1453,6 @@ impl<'db> Type<'db> {
|
||||
true
|
||||
}
|
||||
|
||||
// TODO: This is a workaround to avoid false positives (e.g. when checking function calls
|
||||
// with `SupportsIndex` parameters), which should be removed when we understand protocols.
|
||||
(lhs, Type::NominalInstance(instance))
|
||||
if instance.class().is_known(db, KnownClass::SupportsIndex) =>
|
||||
{
|
||||
match lhs {
|
||||
Type::NominalInstance(instance)
|
||||
if matches!(
|
||||
instance.class().known(db),
|
||||
Some(KnownClass::Int | KnownClass::SupportsIndex)
|
||||
) =>
|
||||
{
|
||||
true
|
||||
}
|
||||
Type::IntLiteral(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: ditto for avoiding false positives when checking function calls with `Sized` parameters.
|
||||
(lhs, Type::NominalInstance(instance))
|
||||
if instance.class().is_known(db, KnownClass::Sized) =>
|
||||
{
|
||||
matches!(
|
||||
lhs.to_meta_type(db).member(db, "__len__"),
|
||||
SymbolAndQualifiers {
|
||||
symbol: Symbol::Type(..),
|
||||
..
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
(Type::NominalInstance(self_instance), Type::NominalInstance(target_instance)) => {
|
||||
self_instance.is_assignable_to(db, target_instance)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user