summaryrefslogtreecommitdiff
path: root/pylint/test
diff options
context:
space:
mode:
authorDmitry Pribysh <dmand@yandex.ru>2015-11-07 19:09:00 +0300
committerDmitry Pribysh <dmand@yandex.ru>2015-11-07 19:09:00 +0300
commit570d3399d05e180f7d8643b238d31f063c407321 (patch)
tree97360a45728f1be11b00fbfabaa3538565a76159 /pylint/test
parent60c8b26efc81e78e9612d3eee0fa13edd2f52edb (diff)
downloadpylint-570d3399d05e180f7d8643b238d31f063c407321.tar.gz
Reduce number of false positives emitted by non-iterator-returned checker
By disabling checker for cases when there're multiple possible values infered for node. This way we lose some of the inference power, but throw a lot less false positives. Fixes issue #695.
Diffstat (limited to 'pylint/test')
-rw-r--r--pylint/test/functional/non_iterator_returned.py21
-rw-r--r--pylint/test/functional/non_iterator_returned.txt9
2 files changed, 17 insertions, 13 deletions
diff --git a/pylint/test/functional/non_iterator_returned.py b/pylint/test/functional/non_iterator_returned.py
index 804ceee..d2fa758 100644
--- a/pylint/test/functional/non_iterator_returned.py
+++ b/pylint/test/functional/non_iterator_returned.py
@@ -56,6 +56,19 @@ class FifthGoodIterator(object):
def __iter__(self):
return IteratorClass
+class FileBasedIterator(object):
+ def __init__(self, path):
+ self.path = path
+ self.file = None
+
+ def __iter__(self):
+ if self.file is not None:
+ self.file.close()
+ self.file = open(self.path)
+ # self file has two infered values: None and <instance of 'file'>
+ # we don't want to emit error in this case
+ return self.file
+
class FirstBadIterator(object):
""" __iter__ returns a list """
@@ -80,11 +93,3 @@ class FourthBadIterator(object):
def __iter__(self): # [non-iterator-returned]
return ThirdBadIterator
-
-class FifthBadIterator(object):
- """All branches should return an iterator."""
-
- def __iter__(self): # [non-iterator-returned]
- if self:
- return 1
- return SecondGoodIterator()
diff --git a/pylint/test/functional/non_iterator_returned.txt b/pylint/test/functional/non_iterator_returned.txt
index fe3db10..fa1d5be 100644
--- a/pylint/test/functional/non_iterator_returned.txt
+++ b/pylint/test/functional/non_iterator_returned.txt
@@ -1,5 +1,4 @@
-non-iterator-returned:63:FirstBadIterator.__iter__:__iter__ returns non-iterator
-non-iterator-returned:69:SecondBadIterator.__iter__:__iter__ returns non-iterator
-non-iterator-returned:75:ThirdBadIterator.__iter__:__iter__ returns non-iterator
-non-iterator-returned:81:FourthBadIterator.__iter__:__iter__ returns non-iterator
-non-iterator-returned:87:FifthBadIterator.__iter__:__iter__ returns non-iterator \ No newline at end of file
+non-iterator-returned:76:FirstBadIterator.__iter__:__iter__ returns non-iterator
+non-iterator-returned:82:SecondBadIterator.__iter__:__iter__ returns non-iterator
+non-iterator-returned:88:ThirdBadIterator.__iter__:__iter__ returns non-iterator
+non-iterator-returned:94:FourthBadIterator.__iter__:__iter__ returns non-iterator