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

Curly braces break %time #4140

Open
armamut opened this issue Oct 25, 2018 · 5 comments
Open

Curly braces break %time #4140

armamut opened this issue Oct 25, 2018 · 5 comments

Comments

@armamut
Copy link

armamut commented Oct 25, 2018

While running this trivial example is fine:

'{"abc", "def", "ghi"}'.replace('{','').replace('}','')

running it with %time magic gives error.

%time '{"abc", "def", "ghi"}'.replace('{','').replace('}','')

Traceback (most recent call last):

  File "/usr/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3265, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-6-5a0bb0dbe481>", line 1, in <module>
    get_ipython().run_line_magic('time', '\'{"abc", "def", "ghi"}\'.replace(\'{\',\'\').replace(\'}\',\'\')')

  File "/usr/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2285, in run_line_magic
    result = fn(*args,**kwargs)

  File "<decorator-gen-62>", line 2, in time

  File "/usr/local/lib/python3.7/site-packages/IPython/core/magic.py", line 187, in <lambda>
    call = lambda f, *a, **k: f(*a, **k)

  File "/usr/local/lib/python3.7/site-packages/IPython/core/magics/execution.py", line 1202, in time
    expr_ast = self.shell.compile.ast_parse(expr)

  File "/usr/local/lib/python3.7/site-packages/IPython/core/compilerop.py", line 100, in ast_parse
    return compile(source, filename, symbol, self.flags | PyCF_ONLY_AST, 1)

  File "<unknown>", line 1
    '('abc', 'def', 'ghi')'.replace(',).replace(','')
         ^
SyntaxError: invalid syntax

jupyter --version is 4.4.0
jupyter notebook --version is 5.7.0

@Carreau
Copy link
Member

Carreau commented Oct 30, 2018

That is an IPython feature. When using magics braces get expanded to variable content. You need to double them to actually insert a brace.

@armamut
Copy link
Author

armamut commented Oct 30, 2018

That is an IPython feature. When using magics braces get expanded to variable content. You need to double them to actually insert a brace.

Oh, I see. Should I close this issue then?

@armamut armamut closed this as completed Oct 30, 2018
@armamut
Copy link
Author

armamut commented Oct 30, 2018

Sorry, I have accidentally closed it. Thank for the reply :)

@Carreau Carreau reopened this Oct 30, 2018
@Carreau
Copy link
Member

Carreau commented Oct 30, 2018

We can try to catch the SyntaxError and see if we can add a warning.
Thanks for the report.

@mgeier
Copy link
Contributor

mgeier commented Nov 19, 2018

That is an IPython feature.

See ipython/ipython#10920.

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

3 participants