Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-reiss committed Apr 16, 2024
1 parent be811c6 commit 197b5fc
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 @@ -12,6 +12,10 @@ class Str:
def __bytes__(self):
return "some bytes" # [invalid-bytes-return]

class BytesNoReturn:
def __bytes__(self):
print("ruff") # [invalid-bytes-return]

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

if returns.is_empty() {
checker.diagnostics.push(Diagnostic::new(
InvalidBytesReturnType,
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 @@ -28,5 +28,15 @@ invalid_return_type_bytes.py:13:16: PLE0308 `__bytes__` does not return `bytes`
13 | return "some bytes" # [invalid-bytes-return]
| ^^^^^^^^^^^^ PLE0308
14 |
15 | # TODO: Once Ruff has better type checking
15 | class BytesNoReturn:
|

invalid_return_type_bytes.py:17:9: PLE0308 `__bytes__` does not return `bytes`
|
15 | class BytesNoReturn:
16 | def __bytes__(self):
17 | print("ruff") # [invalid-bytes-return]
| ^^^^^^^^^^^^^ PLE0308
18 |
19 | # TODO: Once Ruff has better type checking
|

0 comments on commit 197b5fc

Please sign in to comment.