Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%time doesn't work for multiline statements #2381

Closed
asmeurer opened this issue Sep 4, 2012 · 5 comments
Closed

%time doesn't work for multiline statements #2381

asmeurer opened this issue Sep 4, 2012 · 5 comments
Milestone

Comments

@asmeurer
Copy link
Contributor

asmeurer commented Sep 4, 2012

This is possibly related to #2293.

In [42]: 1 + \
   ....: 2
Out[42]: 3

In [43]: %time 1 + \
  File "<timed exec>", line 1
    1 + \
         ^
SyntaxError: unexpected EOF while parsing

In [47]: %time 1 \
CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
Wall time: 0.00 s

In [48]: 1 \
   ....: + 2
Out[48]: 3

In [49]: %time 1 \
+ 2
CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
Wall time: 0.00 s
Out[49]: 2

(to enter [49], I had to up arrow to [48] in the history and add %time before it).

In addition to the obvious issues here of it not working with multiline statements, in [49], notice that it just evaluates the last line.

@minrk
Copy link
Member

minrk commented Sep 4, 2012

Do any line magics support continuations? I wouldn't expect so.

If not, then perhaps this is perhaps better expressed as the more generic "line magics do not support continuations".

@fperez
Copy link
Member

fperez commented Sep 4, 2012

On Tue, Sep 4, 2012 at 11:57 AM, Min RK notifications@github.com wrote:

Do any line magics support continuations? I wouldn't expect so.

If not, then perhaps this is perhaps better expressed as the more generic
"line magics do not support continuations".

That's indeed the case, this is not specific to %timeit but generic to
all magics. We've never made any attempt to put in the logic necessary to
capture line continuations and apply the single-line filtering machinery to
the joined line. It's doable, but it hasn't been done.

I vote for closing this and opening an enhancement PR about line
continuations in general for all input flitering, which we can then resolve
as part of the big refactoring that @takluyver is undertaking on that front.

Note: I don't mean that Thomas has to fix this as well, simply that we can
handle it there, even if handling it means deferring it to a later cycle of
refinement of that refactoring. That decision will be up to Thomas, who's
tackling the brunt of that effort.

@takluyver
Copy link
Member

Yep, see #2164 for the general case of this. I hope my refactoring can make this sort of thing possible, but I haven't figured out all the details yet (I was on a conference and holiday last week).

I'm closing this one, as I think #2164 already covers it.

@asmeurer
Copy link
Contributor Author

asmeurer commented Sep 4, 2012

Might the result of [49] be considered a separate bug here?

@takluyver
Copy link
Member

At a glance, it's another consequence of the same bug - the line
continuation is ignored, so it sees +2 as a separate expression.

@minrk minrk added this to the 1.0 milestone Mar 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants