Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
due to ruff type checking constraints, do a best effort for E0307 for…
… checking return results of __str__ of constants
- Loading branch information
1 parent
78eaefb
commit 339a382
Showing
3 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
27 changes: 25 additions & 2 deletions
27
crates/ruff/resources/test/fixtures/pylint/invalid_return_type_str.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
class Str: | ||
"""__str__ returns int""" | ||
def __str__(self): | ||
return 1 | ||
|
||
class Float: | ||
def __str__(self): | ||
return 3.05 | ||
|
||
class Int: | ||
def __str__(self): | ||
return 0 | ||
|
||
class Bool: | ||
def __str__(self): | ||
return False | ||
|
||
class Str2: | ||
def __str__(self): | ||
x = "ruff" | ||
return x | ||
|
||
# TODO fixme once Ruff has better type checking | ||
def return_int(): | ||
return 3 | ||
|
||
class ComplexReturn: | ||
def __str__(self): | ||
return 1 | ||
return return_int() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 36 additions & 3 deletions
39
...ules/pylint/snapshots/ruff__rules__pylint__tests__PLE0307_invalid_return_type_str.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,44 @@ | ||
--- | ||
source: crates/ruff/src/rules/pylint/mod.rs | ||
--- | ||
invalid_return_type_str.py:5:16: PLE0307 __str__ does not return str | ||
invalid_return_type_str.py:3:16: PLE0307 __str__ does not return str | ||
| | ||
5 | def __str__(self): | ||
6 | return 1 | ||
3 | class Str: | ||
4 | def __str__(self): | ||
5 | return 1 | ||
| ^ PLE0307 | ||
6 | | ||
7 | class Float: | ||
| | ||
|
||
invalid_return_type_str.py:7:16: PLE0307 __str__ does not return str | ||
| | ||
7 | class Float: | ||
8 | def __str__(self): | ||
9 | return 3.05 | ||
| ^^^^ PLE0307 | ||
10 | | ||
11 | class Int: | ||
| | ||
|
||
invalid_return_type_str.py:11:16: PLE0307 __str__ does not return str | ||
| | ||
11 | class Int: | ||
12 | def __str__(self): | ||
13 | return 0 | ||
| ^ PLE0307 | ||
14 | | ||
15 | class Bool: | ||
| | ||
|
||
invalid_return_type_str.py:15:16: PLE0307 __str__ does not return str | ||
| | ||
15 | class Bool: | ||
16 | def __str__(self): | ||
17 | return False | ||
| ^^^^^ PLE0307 | ||
18 | | ||
19 | class Str2: | ||
| | ||
|
||
|