astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
33.04k stars 1.1k forks source link

RET505 false positive #2020

Closed Kludex closed 1 year ago

Kludex commented 1 year ago

Description

I'm having a RET505 on elif statements, where they shouldn't be raised.

Code

from typing import Any

def parser(obj: Any) -> str:
    if isinstance(obj, dict):
        return "a"
    elif isinstance(obj, int):
        return "b"
    return "c"

Command

ruff main.py

Output

main.py:5:5: RET505 Unnecessary `elif` after `return` statement
bluetech commented 1 year ago

Why shouldn't it be raised? The elif is indeed superfluous here (can be just if).

Kludex commented 1 year ago

Hmmm... Ok. :eyes:

Thanks.