-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d66b12
commit b09ac0b
Showing
4 changed files
with
61 additions
and
69 deletions.
There are no files selected for viewing
18 changes: 15 additions & 3 deletions
18
crates/ruff_linter/resources/test/fixtures/pylint/invalid_return_type_length.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,58 +1,70 @@ | ||
# These testcases should raise errors | ||
|
||
|
||
class Bool: | ||
def __len__(self): | ||
return True # [invalid-length-return] | ||
|
||
|
||
class Float: | ||
def __len__(self): | ||
return 3.05 # [invalid-length-return] | ||
|
||
|
||
class Str: | ||
def __len__(self): | ||
return "ruff" # [invalid-length-return] | ||
|
||
|
||
class LengthNoReturn: | ||
def __len__(self): | ||
print("ruff") # [invalid-length-return] | ||
|
||
|
||
class LengthNegative: | ||
def __len__(self): | ||
return -42 # [invalid-length-return] | ||
|
||
|
||
class LengthWrongRaise: | ||
def __len__(self): | ||
print("raise some error") | ||
raise NotImplementedError # [invalid-length-return] | ||
|
||
|
||
# TODO: Once Ruff has better type checking | ||
def return_int(): | ||
return "3" | ||
|
||
|
||
class ComplexReturn: | ||
def __len__(self): | ||
return return_int() # [invalid-length-return] | ||
|
||
|
||
# These testcases should NOT raise errors | ||
|
||
|
||
class Length: | ||
def __len__(self): | ||
return 42 | ||
|
||
|
||
class Length2: | ||
def __len__(self): | ||
x = 42 | ||
return x | ||
|
||
|
||
class Length3: | ||
def __len__(self): | ||
... | ||
def __len__(self): ... | ||
|
||
|
||
class Length4: | ||
def __len__(self): | ||
pass | ||
|
||
|
||
class Length5: | ||
def __len__(self): | ||
raise NotImplementedError | ||
raise NotImplementedError |
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
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
67 changes: 28 additions & 39 deletions
67
...t/snapshots/ruff_linter__rules__pylint__tests__PLE0303_invalid_return_type_length.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,62 +1,51 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pylint/mod.rs | ||
--- | ||
invalid_return_type_length.py:5:16: PLE0303 `__len__` does not return a non-negative `integer` | ||
invalid_return_type_length.py:6:16: PLE0303 `__len__` does not return a non-negative integer | ||
| | ||
3 | class Bool: | ||
4 | def __len__(self): | ||
5 | return True # [invalid-length-return] | ||
4 | class Bool: | ||
5 | def __len__(self): | ||
6 | return True # [invalid-length-return] | ||
| ^^^^ PLE0303 | ||
6 | | ||
7 | class Float: | ||
| | ||
|
||
invalid_return_type_length.py:9:16: PLE0303 `__len__` does not return a non-negative `integer` | ||
invalid_return_type_length.py:11:16: PLE0303 `__len__` does not return a non-negative integer | ||
| | ||
7 | class Float: | ||
8 | def __len__(self): | ||
9 | return 3.05 # [invalid-length-return] | ||
9 | class Float: | ||
10 | def __len__(self): | ||
11 | return 3.05 # [invalid-length-return] | ||
| ^^^^ PLE0303 | ||
10 | | ||
11 | class Str: | ||
| | ||
|
||
invalid_return_type_length.py:13:16: PLE0303 `__len__` does not return a non-negative `integer` | ||
invalid_return_type_length.py:16:16: PLE0303 `__len__` does not return a non-negative integer | ||
| | ||
11 | class Str: | ||
12 | def __len__(self): | ||
13 | return "ruff" # [invalid-length-return] | ||
14 | class Str: | ||
15 | def __len__(self): | ||
16 | return "ruff" # [invalid-length-return] | ||
| ^^^^^^ PLE0303 | ||
14 | | ||
15 | class LengthNoReturn: | ||
| | ||
|
||
invalid_return_type_length.py:17:9: PLE0303 `__len__` does not return a non-negative `integer` | ||
invalid_return_type_length.py:20:9: PLE0303 `__len__` does not return a non-negative integer | ||
| | ||
15 | class LengthNoReturn: | ||
16 | def __len__(self): | ||
17 | print("ruff") # [invalid-length-return] | ||
| ^^^^^^^^^^^^^ PLE0303 | ||
18 | | ||
19 | class LengthNegative: | ||
19 | class LengthNoReturn: | ||
20 | def __len__(self): | ||
| ^^^^^^^ PLE0303 | ||
21 | print("ruff") # [invalid-length-return] | ||
| | ||
|
||
invalid_return_type_length.py:21:16: PLE0303 `__len__` does not return a non-negative `integer` | ||
invalid_return_type_length.py:26:16: PLE0303 `__len__` does not return a non-negative integer | ||
| | ||
19 | class LengthNegative: | ||
20 | def __len__(self): | ||
21 | return -42 # [invalid-length-return] | ||
24 | class LengthNegative: | ||
25 | def __len__(self): | ||
26 | return -42 # [invalid-length-return] | ||
| ^^^ PLE0303 | ||
22 | | ||
23 | class LengthWrongRaise: | ||
| | ||
|
||
invalid_return_type_length.py:26:9: PLE0303 `__len__` does not return a non-negative `integer` | ||
| | ||
24 | def __len__(self): | ||
25 | print("raise some error") | ||
26 | raise NotImplementedError # [invalid-length-return] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ PLE0303 | ||
27 | | ||
28 | # TODO: Once Ruff has better type checking | ||
invalid_return_type_length.py:30:9: PLE0303 `__len__` does not return a non-negative integer | ||
| | ||
29 | class LengthWrongRaise: | ||
30 | def __len__(self): | ||
| ^^^^^^^ PLE0303 | ||
31 | print("raise some error") | ||
32 | raise NotImplementedError # [invalid-length-return] | ||
| |