diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2017-12-24 18:02:08 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2017-12-24 18:02:08 +0100 |
commit | 36c0dfca9334820235aeda4916298659e8e6c559 (patch) | |
tree | d9ac49fdb15c5d04d3471a258210429d8999239a | |
parent | 4d72b2248529c2bbf6d9ff79980673559c8893d9 (diff) | |
download | pylint-git-36c0dfca9334820235aeda4916298659e8e6c559.tar.gz |
Don't crash when encountering bare raises while checking inconsistent returns
Close #1773
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | pylint/checkers/refactoring.py | 3 | ||||
-rw-r--r-- | pylint/test/functional/inconsistent_returns.py | 13 |
3 files changed, 20 insertions, 1 deletions
@@ -13,8 +13,11 @@ Release data: |TBA| * Use the proper node to get the name for redefined functions (#1792) - Close #1774 + Close #1774 + * Don't crash when encountering bare raises while checking inconsistent returns + + Close #1773 What's New in Pylint 1.8.1? diff --git a/pylint/checkers/refactoring.py b/pylint/checkers/refactoring.py index 4f72726af..6d3e4d491 100644 --- a/pylint/checkers/refactoring.py +++ b/pylint/checkers/refactoring.py @@ -52,6 +52,9 @@ def _is_node_return_ended(node): # a Raise statement doesn't need to end with a return statement # but if the exception raised is handled, then the handler has to # ends with a return statement + if not node.exc: + # Ignore bare raises + return True exc = utils.safe_infer(node.exc) if exc is None or exc is astroid.Uninferable: return False diff --git a/pylint/test/functional/inconsistent_returns.py b/pylint/test/functional/inconsistent_returns.py index 1b9bd447d..22a905465 100644 --- a/pylint/test/functional/inconsistent_returns.py +++ b/pylint/test/functional/inconsistent_returns.py @@ -138,3 +138,16 @@ def inconsistent_returns_in_nested_function(): else: return arg return not_consistent_returns_inner + + +class BlargException(Exception): + pass + + +def blarg(someval): + try: + if someval: + raise BlargException() + return 5 + except BlargException: + raise |