Skip to content

[check] Basic, non-CFG, after-return dead code detection #14881

@gsnedders

Description

@gsnedders

I had some code that was similar to:

import sys

def is_python3():
    if sys.version_info >= (3, 0):
        return True

    return False

(This matches the style required by RET505.)

If I then run:

% ruff check --select F401,UP036 foo.py --target-version py39  --unsafe-fixes --fix
Found 2 errors (2 fixed, 0 remaining).

I get an output of:


def is_python3():
    return True

    return False

It would both:

  1. Be good if UP036's (admittedly unsafe) fix didn't leave obviously dead code behind,
  2. Be good to have some rule that catches at least trivial dead code like this (which doesn't need any sort of CFG analysis to find).

Mostly filing this as a feature request for the latter, because I'm… in that state now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions