-
-
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.
Implementation of issue #557.
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Check invalid value returned by __len__ """ | ||
|
||
# pylint: disable=too-few-public-methods,missing-docstring,no-self-use,import-error | ||
import sys | ||
|
||
import six | ||
|
||
from missing import Missing | ||
|
||
|
||
class FirstGoodLen(object): | ||
"""__len__ returns <type 'int'>""" | ||
|
||
def __len__(self): | ||
return 0 | ||
|
||
|
||
class SecondGoodLen(object): | ||
"""__len__ returns <type 'long'>""" | ||
|
||
def __len__(self): | ||
return sys.maxsize + 1 | ||
|
||
|
||
class LenMetaclass(type): | ||
def __len__(cls): | ||
return 1 | ||
|
||
|
||
@six.add_metaclass(LenMetaclass) | ||
class ThirdGoodLen(object): | ||
"""Length through the metaclass.""" | ||
|
||
|
||
class FirstBadLen(object): | ||
""" __len__ returns a negative integer """ | ||
|
||
def __len__(self): # [invalid-length-returned] | ||
return -1 | ||
|
||
|
||
class SecondBadLen(object): | ||
""" __len__ returns non-int """ | ||
|
||
def __len__(self): # [invalid-length-returned] | ||
return 3.0 | ||
|
||
|
||
class AmbigousLen(object): | ||
""" Uninferable return value """ | ||
__len__ = lambda self: Missing |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
invalid-length-returned:38:FirstBadLen.__len__:__len__ does not return non-negative integer | ||
invalid-length-returned:45:SecondBadLen.__len__:__len__ does not return non-negative integer |