Don't transform function calls on IPyAutocall objects #1121

merged 4 commits into from Dec 9, 2011


None yet

4 participants


Closes #1117.


The lstrip isn't necessary.... or at least we don't use it later on in the_rest.startswith('[')


Good point.

bfroehle commented Dec 7, 2011

Anyway, looks fine to me. The logic in this section is terribly convoluted, the best I could do to disentangle it was something like

            if force_auto:
                # Don't rewrite if it is already a call.
                do_rewrite = not the_rest.startswith('(')
                if not the_rest:
                    # We only apply it to argument-less calls if the autocall
                    # parameter is set to 2.
                    do_rewrite = == 2
                elif the_rest.startswith('[') and hasattr(obj, '__getitem__'):
                    # Don't autocall in this case: item access for an object
                    # which is BOTH callable and implements __getitem__.
                    do_rewrite = False
                    do_rewrite = True

            # Figure out the rewritten command
            if do_rewrite:
                if the_rest.endswith(';'):
                    newcmd = '%s(%s);' % (ifun.rstrip(),the_rest[:-1])
                    newcmd = '%s(%s)' % (ifun.rstrip(), the_rest)
                newcmd = '%s %s' % (ifun,the_rest)


Thanks, Brad. I've tested that, and committed it here.


Oops, not sure what happened here.


Need to revert this change as well, as the tests expect 'autocallable ()'. My bad.


It's alright, it's a change I made (I should really have done a separate commit for it, but I wanted to go to bed).

The difference is that previously, if it decided not to rewrite the line, it simply used string formatting: newcmd = '%s %s' % (ifun,the_rest), which forced a single space in there. I've told it to use the default prefilter handler (normal_handler) instead. I think the new behaviour is better - when we're not rewriting it, I'd rather not change the input at all.

minrk commented Dec 8, 2011

I don't pretend to understand the slightly weird previous logic, but the replacement certainly looks clean and sensible, nice work!

@takluyver takluyver merged commit 7ea3e2f into ipython:master Dec 9, 2011

Merged, to keep the queue moving. Tests are passing - if you spot any issues with this, I'll do my best to respond to them quickly.

@fperez - tagged so you're aware of this.

fperez commented Dec 10, 2011

Thanks, @takluyver. Good call on keeping the queue moving, otherwise we'll drown. I had a look and don't see any problems, and with the tests added we should be in good shape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment