mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:44:56 +00:00
[ty] Add subdiagnostic about empty bodies in more cases (#18942)
This commit is contained in:
parent
5d546c600a
commit
c77e72ea1a
2 changed files with 5 additions and 4 deletions
|
@ -93,6 +93,7 @@ error[invalid-return-type]: Function always implicitly returns `None`, which is
|
||||||
| ^
|
| ^
|
||||||
|
|
|
|
||||||
info: Consider changing the return annotation to `-> None` or adding a `return` statement
|
info: Consider changing the return annotation to `-> None` or adding a `return` statement
|
||||||
|
info: Only functions in stub files, methods on protocol classes, or methods with `@abstractmethod` are permitted to have empty bodies
|
||||||
info: rule `invalid-return-type` is enabled by default
|
info: rule `invalid-return-type` is enabled by default
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -1828,14 +1828,14 @@ pub(super) fn report_implicit_return_type(
|
||||||
if !has_empty_body {
|
if !has_empty_body {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
diagnostic.info(
|
||||||
|
"Only functions in stub files, methods on protocol classes, \
|
||||||
|
or methods with `@abstractmethod` are permitted to have empty bodies",
|
||||||
|
);
|
||||||
let Some(class) = enclosing_class_of_method else {
|
let Some(class) = enclosing_class_of_method else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if class.iter_mro(db, None).contains(&ClassBase::Protocol) {
|
if class.iter_mro(db, None).contains(&ClassBase::Protocol) {
|
||||||
diagnostic.info(
|
|
||||||
"Only functions in stub files, methods on protocol classes, \
|
|
||||||
or methods with `@abstractmethod` are permitted to have empty bodies",
|
|
||||||
);
|
|
||||||
diagnostic.info(format_args!(
|
diagnostic.info(format_args!(
|
||||||
"Class `{}` has `typing.Protocol` in its MRO, but it is not a protocol class",
|
"Class `{}` has `typing.Protocol` in its MRO, but it is not a protocol class",
|
||||||
class.name(db)
|
class.name(db)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue