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

%paste regression with blank lines #3246

Closed
jseabold opened this issue Apr 30, 2013 · 7 comments · Fixed by #3390
Closed

%paste regression with blank lines #3246

jseabold opened this issue Apr 30, 2013 · 7 comments · Fixed by #3390
Assignees
Milestone

Comments

@jseabold
Copy link
Contributor

I just update to master at 55129be.

I'm able to reproduce with the following code

def other_func(f):
    return f

def some_other_func(f):
    return f

def func(foo):
    foo = some_other_func(foo)

    C = some_other_func(foo)
    # have a blank line
    C = other_func(C)
    return foo

Copy and %paste it into the terminal

## -- End pasted text --
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-f582da7d368d> in <module>()
     11 
     12 
---> 13 C = some_other_func(foo)
     14 # have a blank line
     15 C = other_func(C)

NameError: name 'foo' is not defined  

Then if I do

foo = None
%paste

I get

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-f582da7d368d> in <module>()
     11 
     12 
---> 13 C = some_other_func(foo)
     14 # have a blank line
     15 C = other_func(C)

NameError: name 'foo' is not defined

## -- End pasted text --
---> NameError(Traceback (most recent call last))
---> NameError(: name 'foo' is not defined  )
  File "<ipython-input-8-595d0b69a1da>", line 2
    ---------------------------------------------------------------------------
                                                                               ^
SyntaxError: invalid syntax

Though if I remove the comment line and define at the prompt foo=1 I get a return outside of function

[3]: paste
def other_func(f):
    return f

def some_other_func(f):
    return f

def func(foo):
    foo = some_other_func(foo)

    C = some_other_func(foo)
    C = other_func(C)
    return foo

## -- End pasted text --
  File "<ipython-input-3-77617947b1c7>", line 15
    return foo
SyntaxError: 'return' outside function
@minrk
Copy link
Member

minrk commented Apr 30, 2013

@takluyver This is presumably the same as #3178, but the fix in #3202 doesn't cover %paste. A quick fix, I expect?

@ghost ghost assigned takluyver Apr 30, 2013
@takluyver
Copy link
Member

Similar, but not quite the same, I think. It looks like it's getting split into multiple cells, so it's trying to execute the block after the blank line separately.

@takluyver
Copy link
Member

...the upshot being that it's probably not a trivial fix, but I hope it won't take me too long. I'll look into it shortly.

@cpcloud
Copy link

cpcloud commented Apr 30, 2013

+1 I get this as well

def test_paste(x, y):
    try:
        print x + y
    except:
        z = x + y

    print z
    return x + y

This simple function also does not work.

@minrk
Copy link
Member

minrk commented Apr 30, 2013

@cpcloud it doesn't matter that it's a function, it's just that the new input splitter is splitting the cell on blank lines, when it should be taking the whole paste blob, regardless of the contents.

@cpcloud
Copy link

cpcloud commented Apr 30, 2013

I know, just giving another example.

takluyver added a commit to takluyver/ipython that referenced this issue May 31, 2013
takluyver added a commit to takluyver/ipython that referenced this issue May 31, 2013
@takluyver
Copy link
Member

PR #3390 should fix this.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants