Skip to content

Incorrect exception handling in Tab Nanny #120495

Closed
@Wulian233

Description

@Wulian233

Bug report

Bug description:

In the Lib/tabnanny.py module, the exception handling for IndentationError might not be reachable after SyntaxError is caught and a return statement is executed.
2024-06-14 195123

See https://github.com/python/cpython/blob/main/Lib/tabnanny.py#L108-L114

    except SyntaxError as msg:
        errprint("%r: Token Error: %s" % (file, msg))
        return

    except IndentationError as msg:
        errprint("%r: Indentation Error: %s" % (file, msg))
        return

Why This Happens:
According to https://docs.python.org/3/library/exceptions.html#exception-hierarchy , we can learn that SyntaxError detection range than IndentationError bigger, Is the inclusion relationship. IndentationError is written after SyntaxError, which causes the program to never execute IndentationError
IMG_20240613_211028

How to Fix:
We need to put the more specific IndentationError before SyntaxError

Linked PRs

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