Issue 30402: Unexpected and/or inconsistent del behavior (original) (raw)

Issue30402

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 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
2022-04-11 14:58:46 admin set github: 74587
2017-05-19 04:46:10 rhettinger set status: open -> closednosy: + rhettingermessages: + resolution: not a bugstage: resolved
2017-05-18 20:57:29 bup create