This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Unexpected and/or inconsistent del behavior
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.6
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: bup, rhettinger
Priority: normal Keywords:

Created on 2017-05-18 20:57 by bup, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg293942 - (view) Author: Dan Snider (bup) * Date: 2017-05-18 20:57
k = 'k'
del [k]

That deletes the variable k from the local scope (even though it *looks* like it's trying to delete a list containing 1 element which is equivalent to the variable k).

But if using list literals to delete groups of objects is valid, then why not set literals?

del {k}
raises SyntaxError: can't delete literal

The better option imo would be to only allow tuples when del-ing groups of objects, but if list literals are allowed then set literals should be as well.
msg293948 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-05-19 04:46
Sorry, this is just how expression lists work.  See Grammar/Grammar at

This is really no different than: 
    for [k] is s: ...
    [k, j] = s

> Why not set literals

Because sets are unordered and because it isn't needed.
Date User Action Args
2022-04-11 14:58:46adminsetgithub: 74587
2017-05-19 04:46:10rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg293948

resolution: not a bug
stage: resolved
2017-05-18 20:57:29bupcreate