That is an oversight and a bug in IPython, it is likely due to the fact
that we attempt to parse top-level async-code.
We fixed similar bugs in recent IPython that allowed top level `break`, and
`continue`.
This should raise a SyntaxError.
-- 
Matthias


On Wed, 6 Mar 2019 at 08:44, Tyler Caraza-Harter <[email protected]>
wrote:

> I was recently surprised by a return statement in the cell of a notebook I
> was reading, something like this (I simplified the original to highlight
> the strange behavior):
>
> def f():
>     pass
>
>
> return 5
>
> To my surprise, running this cell did not cause an exception.  Instead, 5
> went to the Out.  Is this a bug, or is this behavior expected?
>
> Surprisingly, I do get an error (SyntaxError: 'return' outside function)
> when I have a return without a proceeding function:
>
> return 5
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/5df252cb-f76d-4972-887b-37346df82fdc%40googlegroups.com
> <https://groups.google.com/d/msgid/jupyter/5df252cb-f76d-4972-887b-37346df82fdc%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/CANJQusWOGBFHFqUTnAVKxt159W6YO6FkyLUrnDDqBuVHLO3%3D%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to