Python

Python

Made by DeepSource

Unnecessary delete statement in a local scope PTC-W0043

Anti-pattern
Major
Autofix

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.

It is recommended to remove this del statement.

Not preferred:

def my_func():
    task = do_some_task()
    evaluate_task(task)
    del task  # This is unnecessary.

Preferred:

def my_func():
    task = do_some_task()
    evaluate_task(task)