Curly braces break %time
- Dominant language
- Jupyter Notebook
- Stars
- 13.3k
- Forks
- 5.8k
- Avg merge
- 6d 11h
- Merged PRs (30d)
- 7
Description
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 "", line 1, in
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 "", line 2, in time
File "/usr/local/lib/python3.7/site-packages/IPython/core/magic.py", line 187, in
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 "", line 1
'('abc', 'def', 'ghi')'.replace(',).replace(','')
^
SyntaxError: invalid syntax
```
jupyter --version is 4.4.0
jupyter notebook --version is 5.7.0
Contributor guide
Research direction
Reproduce both examples and compare the working expression with the failing %time magic. Start in IPython/core/magics/execution.py around time, then follow the call through IPython/core/compilerop.py and run_line_magic in IPython/core/interactiveshell.py. Done means the curly-brace expression runs under %time without the reported SyntaxError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, python
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100