mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-23 09:19:39 +00:00
follow changes in the main branch
This commit is contained in:
parent
07286d5e6d
commit
893dd2b404
5 changed files with 29 additions and 10 deletions
|
|
@ -74,7 +74,9 @@ def _(
|
|||
def bar() -> None:
|
||||
return None
|
||||
|
||||
async def baz(): ...
|
||||
async def baz() -> int:
|
||||
return 42
|
||||
|
||||
async def outer(): # avoid unrelated syntax errors on yield, yield from, and await
|
||||
def _(
|
||||
a: 1, # error: [invalid-type-form] "Int literals are not allowed in this context in a type expression"
|
||||
|
|
|
|||
|
|
@ -131,7 +131,8 @@ match obj:
|
|||
|
||||
```py
|
||||
class C:
|
||||
def __await__(self): ...
|
||||
def __await__(self):
|
||||
yield
|
||||
|
||||
# error: [invalid-syntax] "`return` statement outside of a function"
|
||||
return
|
||||
|
|
@ -147,6 +148,8 @@ yield from []
|
|||
await C()
|
||||
|
||||
def f():
|
||||
# TODO: no error, C is awaitable
|
||||
# error: [invalid-await] "`C` is not awaitable"
|
||||
# error: [invalid-syntax] "`await` outside of an asynchronous function"
|
||||
await C()
|
||||
```
|
||||
|
|
|
|||
|
|
@ -462,7 +462,7 @@ reveal_type(D().h(1)) # revealed: Literal[2] | Unknown
|
|||
reveal_type(C().h(True)) # revealed: Literal[True]
|
||||
reveal_type(D().h(True)) # revealed: Literal[2] | Unknown
|
||||
reveal_type(C().i(1)) # revealed: list[Literal[1]]
|
||||
reveal_type(D().i(1)) # revealed: list[Unknown]
|
||||
reveal_type(D().i(1)) # revealed: list[@Todo(list literal element type)]
|
||||
|
||||
class F:
|
||||
def f(self) -> Literal[1, 2]:
|
||||
|
|
|
|||
|
|
@ -639,7 +639,25 @@ impl<'db> ScopeInference<'db> {
|
|||
}
|
||||
}
|
||||
}
|
||||
union.build()
|
||||
|
||||
let module = parsed_module(db, self.scope.file(db)).load(db);
|
||||
if self
|
||||
.scope
|
||||
.node(db)
|
||||
.as_function(&module)
|
||||
.is_some_and(|func| {
|
||||
let index = semantic_index(db, self.scope.file(db));
|
||||
let is_generator = self.scope.file_scope_id(db).is_generator_function(index);
|
||||
|
||||
func.is_async && !is_generator
|
||||
})
|
||||
{
|
||||
// TODO: yield/await type inference
|
||||
KnownClass::CoroutineType
|
||||
.to_specialized_instance(db, [Type::any(), Type::any(), union.build()])
|
||||
} else {
|
||||
union.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -762,12 +762,8 @@ impl<'db, 'ast> NarrowingConstraintsBuilder<'db, 'ast> {
|
|||
};
|
||||
|
||||
let rhs_ty = inference.expression_type(right);
|
||||
let rhs_class = match rhs_ty {
|
||||
Type::ClassLiteral(class) => class,
|
||||
Type::GenericAlias(alias) => alias.origin(self.db),
|
||||
_ => {
|
||||
continue;
|
||||
}
|
||||
let Type::ClassLiteral(rhs_class) = rhs_ty else {
|
||||
continue;
|
||||
};
|
||||
|
||||
// `else`-branch narrowing for `if type(x) is Y` can only be done
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue