Skip to content

Incorrect exception handling in Tab Nanny #120495

Closed

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

Activity

  1. changed the title [-]Incorrect Exception Handling in `tabnanny.py`[/-] [+]Incorrect exception handling in Tab Nanny[/+] on Jun 14, 2024
  2. added a commit that references this issue on Jun 15, 2024
  3. added 2 commits that reference this issue on Jun 15, 2024
  4. added 2 commits that reference this issue on Jun 15, 2024
  5. added a commit that references this issue on Jun 30, 2024
  6. added a commit that references this issue on Jul 11, 2024
  7. added a commit that references this issue on Jul 17, 2024
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

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions