Skip to content

Conversation

zenlyj
Copy link
Contributor

@zenlyj zenlyj commented Jun 21, 2025

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Description

Somewhat related to #4791. When investigating the issue, I noticed that the false positive is only emitted when checking for global unused variables. It is fine when the try block is nested within a function like:

def foo():
    try:
        pass
    except TypeError as exc:
        print(exc)
    except ValueError as exc:
        print(exc)

There seems to be existing logic handling this as a special case, so I extracted it into a function and reused it for the global unused variable check.

Closes #10426

@zenlyj zenlyj added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jun 21, 2025
Copy link

codecov bot commented Jun 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.88%. Comparing base (f5aa766) to head (a9b2599).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #10436   +/-   ##
=======================================
  Coverage   95.88%   95.88%           
=======================================
  Files         176      176           
  Lines       19140    19144    +4     
=======================================
+ Hits        18352    18356    +4     
  Misses        788      788           
Files with missing lines Coverage Δ
pylint/checkers/variables.py 97.30% <100.00%> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit a9b2599

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@jacobtylerwalls jacobtylerwalls merged commit 9e72867 into pylint-dev:main Aug 6, 2025
44 checks passed
pylint-backport bot pushed a commit that referenced this pull request Aug 6, 2025
jacobtylerwalls pushed a commit that referenced this pull request Aug 6, 2025
…e exceptions (#10436) (#10481)

(cherry picked from commit 9e72867)

Co-authored-by: Zen Lee <[email protected]>
Pierre-Sassoulas added a commit that referenced this pull request Aug 9, 2025
…10487)

* [ci] Install pylint before every test (#10388) (#10389)

Co-authored-by: Marc Mueller <[email protected]>

* Improve backport job permissions (#10390) (#10391)

(cherry picked from commit 222ab20)

* Resolve `possibly-used-before-assignment` false positives from `match` block assignments (#10393)

(cherry picked from commit ad14b5b)

* Use custom Github App to authenticate backport job (#10394) (#10396)

(cherry picked from commit 6be8676)

Co-authored-by: Marc Mueller <[email protected]>

* Fix Pyreverse: Aggregations aren't filtered according to filter mode (PUB_ONLY, etc.) (#10379) (#10401)

* updated diagrams.py file

* added tests

* updated tests

* added test cases

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------


(cherry picked from commit ed59632)

Co-authored-by: pavan-msys <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Fix Mermaid printer rendering double underscores as bold formatting (#10403) (#10410)

(cherry picked from commit 25a0f9e)

Co-authored-by: Julian Grimm <[email protected]>
Co-authored-by: Pierre Sassoulas <[email protected]>

* Respect docstring-min-length in docparams extension (#10104) (#10434)

(cherry picked from commit 7f5e996)

Co-authored-by: Berker ŞAL <[email protected]>

* Fix `unused-variable` false positive when using same name for multiple exceptions (#10436) (#10481)

(cherry picked from commit 9e72867)

Co-authored-by: Zen Lee <[email protected]>

* Fix false-negative for used-before-assignment with postponed evaluation in function defs (#10482) (#10483)

(cherry picked from commit d363fca)

Co-authored-by: Marc Mueller <[email protected]>

* Update pytest-benchmark requirement from ~=4.0 to ~=5.1 (#10066) (#10484)

(cherry picked from commit f04761b)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump pylint to 3.3.8, update changelog (#10486)

---------

Co-authored-by: Marc Mueller <[email protected]>
Co-authored-by: Jacob Walls <[email protected]>
Co-authored-by: pylint-backport-bot[bot] <212256041+pylint-backport-bot[bot]@users.noreply.github.com>
Co-authored-by: pavan-msys <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Julian Grimm <[email protected]>
Co-authored-by: Berker ŞAL <[email protected]>
Co-authored-by: Zen Lee <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport maintenance/3.3.x False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive W0612 / 'unused variable' when using same name for exception in except block
3 participants