ipython icon indicating copy to clipboard operation
ipython copied to clipboard

IPython not throwing IndentationError with unexpected indent

Open GeniusLearner opened this issue 6 years ago • 1 comments

{'commit_hash': 'e508b6e4d', 'commit_source': 'installation', 'default_encoding': 'UTF-8', 'ipython_path': '/home/geniuslearner/.local/lib/python3.7/site-packages/IPython', 'ipython_version': '7.10.1', 'os_name': 'posix', 'platform': 'Linux-4.19.0-6-amd64-x86_64-with-debian-10.2', 'sys_executable': '/usr/bin/python', 'sys_platform': 'linux', 'sys_version': '3.7.3 (default, Apr 3 2019, 05:39:12) \n[GCC 8.3.0]'}

Actual problem: Whitespace in the beginning of the line throws IndentationError in Python. But, in IPython, it is not showing indentation error.

>>> a = 12
>>>  a = 12
  File "<stdin>", line 1
    a = 12
    ^
IndentationError: unexpected indent

I want to also fix this issue. Please point me to the relevant code.

GeniusLearner avatar Dec 07 '19 17:12 GeniusLearner

That's on purpose, to allow you to past code – usually from website – that may have extra whitespace or prompt in it:

In [1]: In [3]: a = 1
   ...:    ...: b = 2

In [2]: >>> i = 1

It will throw UnexpectedIndent if the amount of whitespace is not consistent between line.

In [3]: a = 1
   ...:  b = 2
  File "<ipython-input-7-8e872b00334f>", line 2
    b = 2
    ^
IndentationError: unexpected indent

But unless it's actually crating bugs in legitimate case, it's an on purpose feature.

Closing, but feel free to ask to reopen if there is something I missed.

Carreau avatar Dec 07 '19 19:12 Carreau