[IPython-dev] Should we disable autocall by default from now on?

MinRK benjaminrk@gmail....
Wed Nov 30 15:02:19 CST 2011


On Wed, Nov 30, 2011 at 11:51, Mark Voorhies <mark.voorhies@ucsf.edu> wrote:

> On Wednesday, November 30, 2011 10:00:54 am Thomas Kluyver wrote:
> <snip>
> > I maintain that altering state on attribute access, while it's perfectly
> > possible, is almost always a bad idea, for pretty much this reason: you
> can
> > do very useful things by assuming that you're free to inspect attributes.
>
> I tend to agree with you.  On the other hand, it's legal in the language,
> and
> there is no C++-like concept of a const method to block this sort of side
> effect
> (meaning that people will do this sort of thing both deliberately and
> inadvertently).
>
>
Python is a language of unenforced convention, which allows for this kind
of magic vs magic conflict.

IPython's expectation that hasattr is safe is a reasonable one, as is
Traits' expectation that getattr
will only be called when the attribute is actually requested.

But Traits' behavior invalidates hasattr, and IPython's behavior can
trigger unrequested events.

It would be nice if there was a corresponding `__hasattr__`, so that
checking for attribute existence
could bypass side effects in objects that do getattr magic that should only
be triggered on *real* getattr.

Given that lack of autocall fails loudly and multiple attribute access
> fails silently,
> I think that setting the default to "fail loudly" (no autocall) makes
> sense.
>

This makes perfect sense, and is a good general rule for such decisions.
I do think it will be newcomers using IPython to learn Python who will be
most adversely affected by the change, because a SyntaxError
is not helpful, while correcting the user is instructive.

-MinRK


>
> --Mark
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-dev/attachments/20111130/83e8da99/attachment.html 


More information about the IPython-dev mailing list