diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-07-15 11:27:57 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-07-15 11:27:57 +0200 |
commit | 6f087b25b3b751ddb2c1cbd03f4b406fd82da78a (patch) | |
tree | 31ffd6db4cf3e459b81920edf4294ebcd603b242 | |
parent | e78be1690e3949fca26312a0a2e5d8f8c0ffae0b (diff) | |
download | pylint-git-6f087b25b3b751ddb2c1cbd03f4b406fd82da78a.tar.gz |
Validate that the next() builtin is called when looking for stop-iteration-return, and ignore attributes named the same
-rw-r--r-- | pylint/checkers/refactoring.py | 4 | ||||
-rw-r--r-- | pylint/test/functional/stop_iteration_inside_generator.py | 11 |
2 files changed, 15 insertions, 0 deletions
diff --git a/pylint/checkers/refactoring.py b/pylint/checkers/refactoring.py index e4883bccd..30f50cdd9 100644 --- a/pylint/checkers/refactoring.py +++ b/pylint/checkers/refactoring.py @@ -479,6 +479,10 @@ class RefactoringChecker(checkers.BaseTokenChecker): return inferred.qname() in KNOWN_INFINITE_ITERATORS return False + if isinstance(node.func, astroid.Attribute): + # A next() method, which is now what we want. + return + inferred = utils.safe_infer(node.func) if getattr(inferred, 'name', '') == 'next': frame = node.frame() diff --git a/pylint/test/functional/stop_iteration_inside_generator.py b/pylint/test/functional/stop_iteration_inside_generator.py index b08fd221f..d8b74d4c1 100644 --- a/pylint/test/functional/stop_iteration_inside_generator.py +++ b/pylint/test/functional/stop_iteration_inside_generator.py @@ -107,3 +107,14 @@ def generator_using_next(): counter = count() number = next(counter) yield number * 2 + + +# pylint: disable=no-self-use,too-few-public-methods +class SomeClassWithNext: + def next(self): + return iter([1, 2, 3]) + def some_gen(self): + for value in self.next(): + yield value + +SomeClassWithNext().some_gen() |