Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect exception handling in Tab Nanny #120495

Closed
Wulian233 opened this issue Jun 14, 2024 · 0 comments
Closed

Incorrect exception handling in Tab Nanny #120495

Wulian233 opened this issue Jun 14, 2024 · 0 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@Wulian233
Copy link
Contributor

Wulian233 commented Jun 14, 2024

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

@Wulian233 Wulian233 added the type-bug An unexpected behavior, bug, or error label Jun 14, 2024
@Wulian233 Wulian233 changed the title Incorrect Exception Handling in tabnanny.py Incorrect exception handling in Tab Nanny Jun 14, 2024
hugovk added a commit that referenced this issue Jun 15, 2024
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 15, 2024
…nGH-120498)

(cherry picked from commit c501261)

Co-authored-by: Wulian233 <71213467+Wulian233@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 15, 2024
…nGH-120498)

(cherry picked from commit c501261)

Co-authored-by: Wulian233 <71213467+Wulian233@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
hugovk added a commit that referenced this issue Jun 15, 2024
…20498) (#120549)

gh-120495: Fix incorrect exception handling in Tab Nanny (GH-120498)
(cherry picked from commit c501261)

Co-authored-by: Wulian233 <71213467+Wulian233@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
hugovk added a commit that referenced this issue Jun 15, 2024
…20498) (#120548)

gh-120495: Fix incorrect exception handling in Tab Nanny (GH-120498)
(cherry picked from commit c501261)

Co-authored-by: Wulian233 <71213467+Wulian233@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
mrahtz pushed a commit to mrahtz/cpython that referenced this issue Jun 30, 2024
…n#120498)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
…n#120498)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
…n#120498)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant