rspec/rules/S3984/python/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

49 lines
1.0 KiB
Plaintext

== Why is this an issue?
Creating a new ``++Exception++`` without actually raising it has no effect and is probably due to a mistake.
=== Noncompliant code example
[source,python]
----
def func(x):
if not isinstance(x, int):
TypeError("Wrong type for parameter 'x'. func expects an integer") # Noncompliant
if x < 0:
ValueError # Noncompliant
return x + 42
----
=== Compliant solution
[source,python]
----
def func(x):
if not isinstance(x, int):
raise TypeError("Wrong type for parameter 'x'. func expects an integer")
if x < 0:
raise ValueError
return x + 42
----
== Resources
* https://docs.python.org/3/tutorial/errors.html#raising-exceptions[Python documentation - Raising Exceptions]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Raise this exception or remove this useless statement
=== Highlighting
Primary: The statement creating an Exception.
endif::env-github,rspecator-view[]