CodeQL documentation

Statement has no effect

ID: py/ineffectual-statement
Kind: problem
Security severity: 
Severity: recommendation
Precision: high
Tags:
   - quality
   - maintainability
   - useless-code
   - external/cwe/cwe-561
Query suites:
   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

An expression statement without side effects is just clutter. It confuses the reader and may have a slight impact on performance.

Recommendation

First determine what the intention of the code was, if there is no intention of a side effect, then just delete the statement. However, it is probable that there is a mistake in the code and some effect was intended.

This query will not flag a statement consisting solely of a string as having no side effect, as these are often used as comments. If you want to use strings as comments, the most common convention is to use triple quoted strings rather than single quoted ones. Although consistency is more important than conforming to any particular style.

Example

In this example neither line of the increment_and_show() function has any effect.

The first line, ++x, has no effect as it applies the unary plus operator twice. Probably the programmer intended x += 1

The second line, x.show, has no observable effect, but it is likely that x.show() was intended.


def increment_and_show(x):
    ++x
    x.show
  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy