diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-03-17 20:32:32 +0100 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-03-28 22:45:45 +0200 |
commit | cc8aecde635f991b1bb8e1331ce2e213ebaf695a (patch) | |
tree | 4a0f6aec7f55f01a59b72b482e6097471c3a924e /tests/functional/n/non/non_iterator_returned.py | |
parent | 32c5b9f2e73085e5a7b368c57b0568569581052e (diff) | |
download | pylint-git-cc8aecde635f991b1bb8e1331ce2e213ebaf695a.tar.gz |
Enable use-symbolic-message-instead in functional tests
Diffstat (limited to 'tests/functional/n/non/non_iterator_returned.py')
-rw-r--r-- | tests/functional/n/non/non_iterator_returned.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/functional/n/non/non_iterator_returned.py b/tests/functional/n/non/non_iterator_returned.py new file mode 100644 index 000000000..89bcdb7d9 --- /dev/null +++ b/tests/functional/n/non/non_iterator_returned.py @@ -0,0 +1,92 @@ +"""Check non-iterators returned by __iter__ """ + +# pylint: disable=too-few-public-methods, missing-docstring, no-self-use, useless-object-inheritance + +class FirstGoodIterator(object): + """ yields in iterator. """ + + def __iter__(self): + for index in range(10): + yield index + +class SecondGoodIterator(object): + """ __iter__ and next """ + + def __iter__(self): + return self + + def __next__(self): + """ Infinite iterator, but still an iterator """ + return 1 + + def next(self): + """Same as __next__, but for Python 2.""" + return 1 + +class ThirdGoodIterator(object): + """ Returns other iterator, not the current instance """ + + def __iter__(self): + return SecondGoodIterator() + +class FourthGoodIterator(object): + """ __iter__ returns iter(...) """ + + def __iter__(self): + return iter(range(10)) + + +class IteratorMetaclass(type): + def __next__(cls): + return 1 + + def next(cls): + return 2 + + +class IteratorClass(object, metaclass=IteratorMetaclass): + """Iterable through the metaclass.""" + + +class FifthGoodIterator(object): + """__iter__ returns a class which uses an iterator-metaclass.""" + 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 """ + + def __iter__(self): # [non-iterator-returned] + return [] + +class SecondBadIterator(object): + """ __iter__ without next """ + + def __iter__(self): # [non-iterator-returned] + return self + +class ThirdBadIterator(object): + """ __iter__ returns an instance of another non-iterator """ + + def __iter__(self): # [non-iterator-returned] + return SecondBadIterator() + +class FourthBadIterator(object): + """__iter__ returns a class.""" + + def __iter__(self): # [non-iterator-returned] + return ThirdBadIterator |