Skip to content
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

import-error inconsistency between except ImportError and with contextlib.suppress(ImportError) #7270

Closed
Guerteltier opened this issue Aug 6, 2022 · 1 comment · Fixed by #7327
Assignees
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@Guerteltier
Copy link

Guerteltier commented Aug 6, 2022

Bug description

There's an inconsistency with import-error between except ImportError and with contextlib.suppress(ImportError).
With the former Pylint doesn't complain when it can't find the module/package, but with the latter it does complain.

This can easily be reproduced with the following code:

# pylint: disable=missing-module-docstring
import contextlib

try:
    import bacon  # pylint: disable=unused-import
except ImportError:
    pass

with contextlib.suppress(ImportError):
    import eggs  # pylint: disable=unused-import

Configuration

No response

Command used

pylint toast.py

Pylint output

************* Module toast
toast.py:10:4: E0401: Unable to import 'eggs' (import-error)

Expected behavior

It's consistent.

Pylint version

pylint 2.15.0-a0
astroid 2.12.2
Python 3.10.5 (main, Jul 27 2022, 01:21:11) [GCC 10.2.1 20210130 (Red Hat 10.2.1-11)]

OS / Environment

No response

Additional dependencies

No response

@Guerteltier Guerteltier added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Aug 6, 2022
@jacobtylerwalls
Copy link
Member

Thanks for the report. The node_ignores_exception utility only checks exception handlers. It should check the contextlib.suppress context manager also. This will end up affecting several additional messages.

@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 6, 2022
@DanielNoord DanielNoord self-assigned this Aug 21, 2022
@DanielNoord DanielNoord added this to the 2.15.0 milestone Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants