Skip to content

Regression in 9.0.1 from 8.33.0 - No longer dedents inputs. #14818

Closed

Description

@Erotemic

Running ipython in the terminal if I copy and paste this block of code:

    # Comment
    x = 1

with the leading indentation on both lines, in 8.33.0 it works fine. IPython recognizes the code has consistent leading whitespace, presumably dedents it under the hood, and executes it.

In [1]:     # Comment
   ...:     x = 1

In [2]: 

However, in 9.0.1

In [1]:     # Comment
   ...:     x = 1
   ...: 
  Cell In[1], line 2
    x = 1
    ^
IndentationError: unexpected indent

I'm not sure if this was intentional or not, but this is a major usability issue for me. My entire workflow is based around copy/pasting chunks of code. I've been working this way for 15 years. I've written libraries around it. There is a PR awaiting merge in CPython to add this dedent feature to "python -c".

If this is intentional, I beg the maintainers to reconsider. Otherwise, this is a major bug.

Tested on Ubuntu 24.04 on CPython 3.13.2 and 3.11.2

Activity

  1. Carreau commented on Mar 5, 2025

    @Carreau
    Member

    This is not intentional.

    I'm not sure I'll have the time to bisect though.

  2. Erotemic commented on Mar 5, 2025

    @Erotemic
    ContributorAuthor

    I can help with that.

    The bad commit is: 2d3f2c6

    I will see if it is an easy fix.

    Interestingly the indentation needs to start with a comment for the bug to trigger:

    # This works
    ipython -c "
        x = 1
        print(x)
        "
    
    # But this raises an error 
    ipython -c "
        # Hello World
        x = 1
        print(x)
        "
    

    The offending MR is: #14721 and corresponding issue is: #14242

    Looking into this, it looks that the test added in the offending MR isn't being run correctly: https://github.com/ipython/ipython/blob/main/tests/test_inputtransformer2_line.py#L185

    They define a new test case, but don't actually test it.

  3. added a commit that references this issue on Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions