summaryrefslogtreecommitdiff
path: root/astroid/decorators.py
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-30 11:55:09 +0200
committerGitHub <noreply@github.com>2021-06-30 11:55:09 +0200
commit9e1af522038a50f8443f2cf4c1d604cd835b8efe (patch)
tree6675c0e6b5ce93902473c2d4c91c0c54a7baab3b /astroid/decorators.py
parentb4a283f388f495df76489dd6226056953153138e (diff)
downloadastroid-git-9e1af522038a50f8443f2cf4c1d604cd835b8efe.tar.gz
Catch the StopIteration that result from PEP-479 or add default value in ``next`` (#1081)
* Catch the StopIteration that result from PEP-479 StopIteration exceptions raised directly or indirectly in coroutines and generators are transformed into RuntimeError exceptions for python 3.7+.
Diffstat (limited to 'astroid/decorators.py')
-rw-r--r--astroid/decorators.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/astroid/decorators.py b/astroid/decorators.py
index 81bc7d62..7d029120 100644
--- a/astroid/decorators.py
+++ b/astroid/decorators.py
@@ -95,21 +95,22 @@ def path_wrapper(func):
yielded = set()
generator = _func(node, context, **kwargs)
- try:
- while True:
+ while True:
+ try:
res = next(generator)
- # unproxy only true instance, not const, tuple, dict...
- if res.__class__.__name__ == "Instance":
- ares = res._proxied
- else:
- ares = res
- if ares not in yielded:
- yield res
- yielded.add(ares)
- except StopIteration as error:
- if error.args:
- return error.args[0]
- return None
+ except StopIteration as error:
+ if error.args:
+ return error.args[0]
+ return None
+
+ # unproxy only true instance, not const, tuple, dict...
+ if res.__class__.__name__ == "Instance":
+ ares = res._proxied
+ else:
+ ares = res
+ if ares not in yielded:
+ yield res
+ yielded.add(ares)
return wrapped
@@ -131,7 +132,6 @@ def yes_if_nothing_inferred(func, instance, args, kwargs):
@wrapt.decorator
def raise_if_nothing_inferred(func, instance, args, kwargs):
generator = func(*args, **kwargs)
-
try:
yield next(generator)
except StopIteration as error: