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

Clarify no-else-raise and no-else-return also apply to try/except #9901

Open
jolaf opened this issue Aug 30, 2024 · 1 comment
Open

Clarify no-else-raise and no-else-return also apply to try/except #9901

jolaf opened this issue Aug 30, 2024 · 1 comment
Labels
Documentation 📗 Good first issue Friendly and approachable by new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@jolaf
Copy link

jolaf commented Aug 30, 2024

Bug description

def f() -> None:
    try:
        assert False
    except Exception:  # pylint: disable=try-except-raise
        raise
    else:
        pass

    try:
        assert False
    except Exception:
        return
    else:
        pass

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:2: [R1720(no-else-raise), f] Unnecessary "else" after "raise", remove the "else" and de-indent the code inside it
test.py:9: [R1705(no-else-return), f] Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

Expected behavior

No error reports.

As far as I understand, no-else-raise/no-else-return are supposed to be produced for if-else operators.

But in this example else is part of try-except-else operators, and the errors are completely inappropriate.

Pylint version

pylint 3.2.6
astroid 3.2.4
Python 3.12.3 (main, Jul 31 2024, 17:43:48) [GCC 13.2.0]

OS / Environment

Ubuntu 24.04.1

Additional dependencies

No response

@jolaf jolaf added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Aug 30, 2024
@jolaf jolaf changed the title Unnecessary "else" after "raise" Unnecessary "else" after "raise"/"return" Aug 30, 2024
@jacobtylerwalls
Copy link
Member

These aren't errors, they're refactoring messages. They still apply here, but we should update the documentation to clarify, since the documentation only mentions if/else.

@jacobtylerwalls jacobtylerwalls changed the title Unnecessary "else" after "raise"/"return" Clarify no-else-raise and no-else-return also apply to try/except Aug 31, 2024
@jacobtylerwalls jacobtylerwalls added Good first issue Friendly and approachable by new contributors Documentation 📗 Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation 📗 Good first issue Friendly and approachable by new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

2 participants