classification
Title: Unexpected and/or inconsistent del behavior
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.6
process
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 2017-05-19 04:46 by rhettinger. 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 https://hg.python.org/cpython/file/tip/Grammar/Grammar

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

> Why not set literals

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

nosy: + rhettinger
messages: + msg293948

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