Why isn't all the code after a return statement removed?

Open
#93 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
tooling

Research direction

Start with the fix_code entry point and trace how unreachable statements after return are handled. Use the example in the issue to verify the expected removal, then determine and test the broader cases where code after a definitely executed final return is dead.

Written by the indexing model from the issue text.

Description

Let's say we have this function

def my_func(x):
    a = 0
    return x  # Code after this is dead code!
    return x

Then your tool (i.e. by calling fix_code) does not remove the second return x, but produces

def my_func(x):
    return x  # Code after this is dead code!
    return x

In general, all the code after the last return statement that we know will be executed is not executed, so it's dead code that can be removed. So, why doesn't your tool handle these cases?

Dominant language
Python
Stars
954
Forks
102
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PyCQA/autoflake

All issues in PyCQA/autoflake

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.