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 — Unnecessary delete statement in function — CodeQL query help documentation

Unnecessary delete statement in function¶

ID: py/unnecessary-delete
Kind: problem
Security severity: 
Severity: warning
Precision: high
Tags:
   - maintainability
   - useless-code
Query suites:
   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

Passing a local variable to a del statement results in that variable being removed from the local namespace. When exiting a function all local variables are deleted, so it is unnecessary to explicitly delete variables in such cases.

Recommendation¶

Remove the del statement.

Example¶

In the function below, the variable x is assigned a value that is used for a calculation, and is then explicitly deleted before the function exits. In this case, the delete statement can be removed without changing the behavior of the function.

def unnecessary_delete():
    x = get_some_object()
    do_calculation(x)
    del x                       # This del statement is unnecessary

References¶

  • Python: The ‘del’ statement.

  • Python/C API Reference Manual: Reference counts.

  • © 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.