GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Statement has no effect — CodeQL query help 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-code-quality.qls
   - 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
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.