Skip to content

unused-variable false negative on a caught exception in the latest 3.x alpha release #8595

@yilei

Description

@yilei

Bug description

import logging

def func(module):
  try:
    module.compute()
    error = False
  except module.TimeoutError as e:
    logging.error('Timed out: %s', e)
    error = True

  if error:
    # Try again with larger timeout.
    try:
      module.compute(timeout=1200)
    except module.Error as e:
      pass

Configuration

No response

Command used

pylint a.py

Pylint output

-------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 9.23/10, +0.77)

Expected behavior

It should raise unused-variable for the second e:

************* Module unused
t.py:15:4: W0612: Unused variable 'e' (unused-variable)


Your code has been rated at 9.23/10 (previous run: 10.00/10, -0.77)

Pylint version

This is a regression in the latest alpha:

pylint 3.0.0a6
astroid 2.15.3
Python 3.11.1 (main, Jan 10 2023, 15:08:01) [Clang 14.0.0 (clang-1400.0.29.202)]

And working as expected in 2.17.2

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: unused-variableFalse Negative 🦋No message is emitted but something is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationRegressionUnreleased

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions