Skip to content

Commit

Permalink
Handle no return case
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-reiss committed Apr 16, 2024
1 parent 1814539 commit f025b0d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Str:
def __index__(self):
return "ruff" # [invalid-index-return]

class IndexNoReturn:
def __index__(self):
print("ruff") # [invalid-index-return]

# TODO: Once Ruff has better type checking
def return_index():
return "3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ pub(crate) fn invalid_index_return(checker: &mut Checker, name: &str, body: &[St
visitor.returns
};

if returns.is_empty() {
checker.diagnostics.push(Diagnostic::new(
InvalidIndexReturnType,
body.last().unwrap().range(),
));
}

for stmt in returns {
if let Some(value) = stmt.value.as_deref() {
if !matches!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,15 @@ invalid_return_type_index.py:18:16: PLE0305 `__index__` does not return `integer
18 | return "ruff" # [invalid-index-return]
| ^^^^^^ PLE0305
19 |
20 | # TODO: Once Ruff has better type checking
20 | class IndexNoReturn:
|

invalid_return_type_index.py:22:9: PLE0305 `__index__` does not return `integer`
|
20 | class IndexNoReturn:
21 | def __index__(self):
22 | print("ruff") # [invalid-index-return]
| ^^^^^^^^^^^^^ PLE0305
23 |
24 | # TODO: Once Ruff has better type checking
|

0 comments on commit f025b0d

Please sign in to comment.