Skip to content

Commit 0723f03

Browse files
committed
[ty] Add subdiagnostic about empty bodies in more cases
1 parent 5d546c6 commit 0723f03

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

crates/ty_python_semantic/resources/mdtest/snapshots/return_type.md_-_Function_return_type_-_Invalid_return_type_(a91e0c67519cd77f).snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ error[invalid-return-type]: Function always implicitly returns `None`, which is
9393
| ^
9494
|
9595
info: Consider changing the return annotation to `-> None` or adding a `return` statement
96+
info: Only functions in stub files, methods on protocol classes, or methods with `@abstractmethod` are permitted to have empty bodies
9697
info: rule `invalid-return-type` is enabled by default
9798

9899
```

crates/ty_python_semantic/src/types/diagnostic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,14 +1828,14 @@ pub(super) fn report_implicit_return_type(
18281828
if !has_empty_body {
18291829
return;
18301830
}
1831+
diagnostic.info(
1832+
"Only functions in stub files, methods on protocol classes, \
1833+
or methods with `@abstractmethod` are permitted to have empty bodies",
1834+
);
18311835
let Some(class) = enclosing_class_of_method else {
18321836
return;
18331837
};
18341838
if class.iter_mro(db, None).contains(&ClassBase::Protocol) {
1835-
diagnostic.info(
1836-
"Only functions in stub files, methods on protocol classes, \
1837-
or methods with `@abstractmethod` are permitted to have empty bodies",
1838-
);
18391839
diagnostic.info(format_args!(
18401840
"Class `{}` has `typing.Protocol` in its MRO, but it is not a protocol class",
18411841
class.name(db)

0 commit comments

Comments
 (0)