On Tue, Mar 29, 2016 at 7:26 PM, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > del x > > Should it return None? The string 'x'? How about the value that x had just > before it was deleted? True if that allowed the value to be garbage > collected, False if it wasn't? Or the other way around? None of these > suggests feel either useful or obviously right.
Returning the value x had just before being deleted is certainly useful - consider the case where x is not a simple name but a subscripting, which makes this into a destructive lookup. Saying whether the object was garbage collected or not could also be useful, but feels very low level. But if Python were to make 'del' into an expression, the only semantics needed would be for simple names. For everything else, the value of 'del x[y]' or 'del x.y' would simply be 'whatever __delitem__/__delattr__ returns'. And even for simple names, the semantics could be defined by the enclosing scope's dictionary. It'd be like Python's operators; yes, you normally expect "x < y" to return a truthy or falsy value, and for most built-in types it'll return either True or False, but you can return anything at all - including a lazy evaluation object for a DSL. Someone could, for instance, make "del User[42]" return a Query object which, when executed, deletes the user with primary key 42. (Note: I am not advocating this. Just saying what would, IMO, be consistent with the rest of Python.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list