ipython/ipython

`inputtransformer2.TransformerManager.check_complete` does not detect incomplete cell when used with line magics

已关闭

#12,706 创建于 2020年11月14日

 (5 条评论) (0 个反应) (0 位负责人)Python (4,400 个派生)batch import
bughelp wanted

仓库指标

星标
 (16,095 个星标)
PR 合并指标
 (平均合并 11天 1小时) (30 天内合并 22 个 PR)

描述

Suppose this is the content of the cell that I have

import pprint
import sys

%time pretty_print_object = pprint.PrettyPrinter(\
          indent=4, width=80, stream=sys.stdout, compact=True, depth=5\

I passed this cell to inputtransformer2.TransformerManager.check_complete and it is returning as complete.

I then manually tried the following

from IPython.core.inputtransformer2 import TransformerManager

tm = TransformerManager()
tm.check_complete("print(\\") # This works as expected returns ('incomplete', 0)
tm.check_complete("%time print(\\") # This returned (complete, None)

Is this output from check_complete is expected for line magics?

Additionally if I type print(\ in the ipython terminal, it is allowing me to type multiple lines, but if I try the same thing with line magics %time print(\ it is raising SyntaxError. But if I copy paste line magics spanning multiple lines, it is able to execute it as expected. For instance copy pasting below snippet to the ipython terminal executes the code as expected.

%time pretty_print_object = pprint.PrettyPrinter(\
          indent=4, width=80, stream=sys.stdout, compact=True, depth=5\
         )

Looks like this was not the behavior in the past as I can see from this stackoverflow answer

IPython version - 7.18.1. I updated to the latest ipython version 7.19.0 and I am able to reproduce the issue.

贡献者指南