Skip to content

Improve detection of unreachable code #519

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

Closed
pylint-bot opened this issue Apr 15, 2015 · 6 comments
Closed

Improve detection of unreachable code #519

pylint-bot opened this issue Apr 15, 2015 · 6 comments
Labels
Control flow Requires control flow understanding False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@pylint-bot
Copy link

pylint-bot commented Apr 15, 2015

Originally reported by: Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore)


def a():
      try:
              return
      except:
              return

      raise Exception('a') # should warn here

Original ticket: http://www.logilab.org/ticket/8355


@PCManticore PCManticore added the Control flow Requires control flow understanding label May 9, 2016
@PCManticore PCManticore added this to the 2.0 milestone May 9, 2016
@PCManticore PCManticore modified the milestones: 4K, 3.0 Jun 17, 2016
@zachliu
Copy link

zachliu commented Jan 14, 2019

How about the code after sys.exit()?

@richin13
Copy link

I'm also affected by this issue

@PCManticore
Copy link
Contributor

Not going to happen too soon, so feel free to disable the check.

@PCManticore PCManticore removed this from the 4.0 milestone Sep 26, 2019
msuozzo pushed a commit to msuozzo/pylint that referenced this issue Feb 18, 2022
Source-Link: googleapis/synthtool@69fda12
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:ae600f36b6bc972b368367b6f83a1d91ec2c82a4a116b383d67d547c56fe6de3

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
@Pierre-Sassoulas Pierre-Sassoulas added False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Bug 🪲 labels Jun 30, 2022
@clavedeluna
Copy link
Contributor

I would argue that this is what should happen in the example code

def a():
      try:
              return
      except: # should warn here
              return # should warn here

      raise Exception('a') # should warn here

because unless something happens in the try block, nothing else will proceed.

@Pierre-Sassoulas
Copy link
Member

@clavedeluna pylint don't understand control flow well, so we treat return like we would treat a random function where we don't know what could happen inside. Not doing so would create an astounding number of false positive at the moment.

@clavedeluna
Copy link
Contributor

should this now be closed? I only referenced it

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.16.0 milestone Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Control flow Requires control flow understanding False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

6 participants