mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
Mark implicit Self
as inferable
This commit is contained in:
parent
3062e71cff
commit
ac3cf4325e
3 changed files with 8 additions and 6 deletions
|
@ -117,7 +117,7 @@ reveal_type(bound_method.__func__) # revealed: def f(self, x: int) -> str
|
|||
reveal_type(C[int]().f(1)) # revealed: str
|
||||
reveal_type(bound_method(1)) # revealed: str
|
||||
|
||||
# error: [invalid-argument-type] "Argument to function `f` is incorrect: Argument type `Literal[1]` does not satisfy upper bound `C[Unknown]` of type variable `Self`"
|
||||
# error: [invalid-argument-type] "Argument to function `f` is incorrect: Argument type `Literal[1]` does not satisfy upper bound `C[T@C]` of type variable `Self`"
|
||||
C[int].f(1) # error: [missing-argument]
|
||||
reveal_type(C[int].f(C[int](), 1)) # revealed: str
|
||||
|
||||
|
|
|
@ -363,12 +363,8 @@ class Invariant[T]:
|
|||
def _(x: object):
|
||||
if isinstance(x, Invariant):
|
||||
reveal_type(x) # revealed: Top[Invariant[Unknown]]
|
||||
# error: [invalid-argument-type] "Argument to bound method `get` is incorrect: Expected `Self@get`, found `Top[Invariant[Unknown]]`"
|
||||
# error: [invalid-argument-type] "Argument to bound method `get` is incorrect: Argument type `Top[Invariant[Unknown]]` does not satisfy upper bound `Bottom[Invariant[Unknown]]` of type variable `Self`"
|
||||
reveal_type(x.get()) # revealed: object
|
||||
# error: [invalid-argument-type] "Argument to bound method `push` is incorrect: Expected `Never`, found `Literal[42]`"
|
||||
# error: [invalid-argument-type] "Argument to bound method `push` is incorrect: Expected `Self@push`, found `Top[Invariant[Unknown]]`"
|
||||
# error: [invalid-argument-type] "Argument to bound method `push` is incorrect: Argument type `Top[Invariant[Unknown]]` does not satisfy upper bound `Bottom[Invariant[Unknown]]` of type variable `Self`"
|
||||
x.push(42)
|
||||
```
|
||||
|
||||
|
|
|
@ -1295,9 +1295,15 @@ impl<'db> Parameters<'db> {
|
|||
let typevar_binding_context = Some(definition);
|
||||
let index = semantic_index(db, scope_id.file(db));
|
||||
let class = nearest_enclosing_class(db, index, scope_id).unwrap();
|
||||
Type::TypeVar(
|
||||
Type::NonInferableTypeVar(
|
||||
get_self_type(db, scope_id, typevar_binding_context, class).unwrap(),
|
||||
)
|
||||
.apply_type_mapping(
|
||||
db,
|
||||
&TypeMapping::MarkTypeVarsInferable(Some(BindingContext::Definition(
|
||||
definition,
|
||||
))),
|
||||
)
|
||||
};
|
||||
Parameter {
|
||||
annotated_type: Some(implicit_annotation),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue