[Python-ideas] Allowing def to assign to anything

Bruce Leban bruce at leban.us
Mon Oct 26 02:49:18 EDT 2015


On Sun, Oct 25, 2015 at 11:19 PM, Alexander Walters <tritium-list at sdamon.com
> wrote:

> This too leaves artifacts in the module, which is one of the annoyances I
> am trying to eliminate.  Though I do admit that it makes the intent of the
> author clear.  It still feels less pythonic to me than allowing a statement
> that assigns to just assign to anything assignable.
>

Well, to some extent features that are already in the language feel more
pythonic than features that aren't. Given that this is already easy to do,
and the decorator solution is more powerful, the bar for modifying the
language is higher.

That aside, I like the fact that I can find these functions in the module.
For one thing, it makes them testable in an obvious way (without going
through the dispatch dictionary). Generally, module_name.function_name
doesn't change during the course of program execution but there's no such
expectation for dispatch_dict[function_name].

Furthermore, consider that

def dispatch['foo'](bar): pass


might look like a simple dict reference but is actually a call to
__setitem__ which means this can have arbitrary side effects. Yes
@decorators can have arbitrary side effects too. How do I find out the
respective side effects? Perhaps:

help(decorator)  # obvious

help(dispatch)  # nope
help(dispatch.__setitem__)  # not obvious to me


--- Bruce
Check out my new puzzle book: http://J.mp/ingToConclusions
Get it free here: http://J.mp/ingToConclusionsFree (available on iOS)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151025/ae0a595b/attachment.html>


More information about the Python-ideas mailing list