[Python-ideas] Unpacking a dict

Zachary Ware zachary.ware+pyideas at gmail.com
Fri May 27 11:27:23 EDT 2016

On Fri, May 27, 2016 at 10:09 AM, Nikolaus Rath <Nikolaus at rath.org> wrote:
> Everyone knows that "from .. import .." modifies the local namespace. We
> just have to extend it to work not just on modules, but also on
> dictionaries.

Here's a crazy thought that might be best dismissed out of hand: what
about extending 'from name import other_names' to accept any object
for <name>?  First try to get values via __getitem__() (possibly only
for dict/dict subclasses?), next try getattr(), finally try to import
the module and pull values from it as per usual.

- solves dict unpacking
- solves attribute unpacking

- it's weird
- has the potential to be confusing: "from name import other_name"
will do different things depending on whether "name" is already bound
in current scope
- we'd suddenly have 'from ... import ...' statements littered
throughout code, rather than nearly always all at the top of the
- dilutes the meaning of "importing"

The two pros are nice, but I'm not sure they beat the four cons.

FTR, I've not seen anything else in this thread that excites me, but I
have only been skimming.


More information about the Python-ideas mailing list