Skip to content

IndentationError in Multiline Comment #112462

@ivarjt

Description

@ivarjt

Bug report

Bug description:

Problem Description

The code has an issue: it's showing an IndentationError in the main() function due to a multiline comment. What's odd is that the error happens even when the comment is indented like another comment that doesn't cause an error.

Steps to Reproduce

  1. Copy and paste the provided code into a Python environment.
  2. Execute the program.

Observed Behavior

The program encounters an IndentationError: unindent does not match any outer indentation level during execution due to an apparent inconsistency in multiline comment indentation.

Expected Behavior

The program should execute without any indentation errors. The multiline comment within the main() function, even if indented, should not result in an IndentationError.

How to Solve

To fix the indentation problem, take a close look at the code. Make sure the indentation is consistent by checking for any extra spaces or tabs that could be causing the "IndentationError: unindent does not match any outer indentation level."

Additional notes

I think that this is a weird bug and i don't really see why this couldn't be fixed.

Enviroment

Tested in these environments with these versions.
Python 3.10.12, Python 3.11.2 or Python 3.12.0
Windows 11
Ubuntu 22.04

def main():
        """
        This multiline comment will give my program this error:
        IndentationError: unindent does not match any outer indentation level
        However the comment below will not give an error even tho it is also indented
        """
    print("Hello World!")

if __name__ == "__main__":
    main()
File "C:\Users\ivar\Desktop\test\main.py", line 7
    print("Hello World!")
                         ^
IndentationError: unindent does not match any outer indentation level

CPython versions tested on:

3.10, 3.11, 3.12

Operating systems tested on:

Linux, Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions