diff options
author | James Addison <55152140+jayaddison@users.noreply.github.com> | 2023-01-07 11:53:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-07 12:53:20 +0100 |
commit | 89a20e2ccdb2927ac370f7c6663fc83318988e10 (patch) | |
tree | ab03368654e560fb76eb977dac31d90f32bb0bdc /tests | |
parent | 56121344f6c9c223d8e4477c0cdb58c46c840b4b (diff) | |
download | pylint-git-89a20e2ccdb2927ac370f7c6663fc83318988e10.tar.gz |
Add new check "pointless-exception-statement" (#7939)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/c/ctor_arguments.py | 2 | ||||
-rw-r--r-- | tests/functional/c/ctor_arguments.txt | 2 | ||||
-rw-r--r-- | tests/functional/s/statement_without_effect.py | 17 | ||||
-rw-r--r-- | tests/functional/s/statement_without_effect.txt | 2 |
4 files changed, 22 insertions, 1 deletions
diff --git a/tests/functional/c/ctor_arguments.py b/tests/functional/c/ctor_arguments.py index d87732f1d..4ed96c2d3 100644 --- a/tests/functional/c/ctor_arguments.py +++ b/tests/functional/c/ctor_arguments.py @@ -82,7 +82,7 @@ class BuiltinExc(Exception): def __init__(self, val=True): self.val = val -BuiltinExc(42, 24, badarg=1) # [too-many-function-args,unexpected-keyword-arg] +BuiltinExc(42, 24, badarg=1) # [line-too-long,pointless-exception-statement,too-many-function-args,unexpected-keyword-arg] class Clsmethod: diff --git a/tests/functional/c/ctor_arguments.txt b/tests/functional/c/ctor_arguments.txt index 286a56bd7..f096eed4e 100644 --- a/tests/functional/c/ctor_arguments.txt +++ b/tests/functional/c/ctor_arguments.txt @@ -15,6 +15,8 @@ too-many-function-args:60:0:60:30::Too many positional arguments for constructor too-many-function-args:63:0:63:17::Too many positional arguments for constructor call:UNDEFINED no-value-for-parameter:64:0:64:15::No value for argument 'first_argument' in constructor call:UNDEFINED unexpected-keyword-arg:64:0:64:15::Unexpected keyword argument 'one' in constructor call:UNDEFINED +line-too-long:85:0::::Line too long (122/100):UNDEFINED +pointless-exception-statement:85:0:85:28::Exception statement has no effect:INFERENCE too-many-function-args:85:0:85:28::Too many positional arguments for constructor call:UNDEFINED unexpected-keyword-arg:85:0:85:28::Unexpected keyword argument 'badarg' in constructor call:UNDEFINED too-many-function-args:95:15:95:30:Clsmethod.from_nothing:Too many positional arguments for constructor call:UNDEFINED diff --git a/tests/functional/s/statement_without_effect.py b/tests/functional/s/statement_without_effect.py index 60694ff96..0c6586e36 100644 --- a/tests/functional/s/statement_without_effect.py +++ b/tests/functional/s/statement_without_effect.py @@ -73,3 +73,20 @@ def ellipsis(): class EllipsisBody: """Test that an Ellipsis as a body does not trigger the error""" ... + + +def assigned_exception(): + """Test that an assigned exception is not flagged as a pointless statement""" + exception = ValueError("one") + return exception, ValueError("two") + + +def raised_exception(): + """Test that a raised exception is not flagged as a pointless statement""" + raise ValueError() + + +def unraised_exception(): + """Test that instantiating but not raising an exception is flagged as a pointless statement""" + ValueError("pointless-statement") # [pointless-exception-statement] + ValueError(to_be()) # [pointless-exception-statement] diff --git a/tests/functional/s/statement_without_effect.txt b/tests/functional/s/statement_without_effect.txt index 6bebf450b..39f86f33b 100644 --- a/tests/functional/s/statement_without_effect.txt +++ b/tests/functional/s/statement_without_effect.txt @@ -10,3 +10,5 @@ expression-not-assigned:32:0:32:22::"Expression ""to_be() or not to_be()"" is as expression-not-assigned:33:0:33:13::"Expression ""to_be().title"" is assigned to nothing":UNDEFINED pointless-string-statement:58:8:58:43:ClassLevelAttributeTest.__init__:String statement has no effect:UNDEFINED pointless-string-statement:65:8:65:55:ClassLevelAttributeTest.test:String statement has no effect:UNDEFINED +pointless-exception-statement:91:4:91:37:unraised_exception:Exception statement has no effect:INFERENCE +pointless-exception-statement:92:4:92:23:unraised_exception:Exception statement has no effect:INFERENCE |