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

warnings.UserWarning not suppressed when importing modules to parse their syntax trees. #7906

Closed
emcd opened this issue Dec 7, 2022 · 0 comments · Fixed by pylint-dev/astroid#2121
Labels
Enhancement ✨ Improvement to a component Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@emcd
Copy link
Contributor

emcd commented Dec 7, 2022

Bug description

The following code:

''' Minimal reproducer for setuptools warning. '''
import setuptools
import pip

produces the following warning when scanned with pylint:

.../site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")

This output is confusing as it is triggered by the code being scanned and not by anything that Pylint uses internally.

Configuration

No response

Command used

pylint --report=no --score=no --disable=unused-import bugs/pylint/distutils_warning.py

Pylint output

.../site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")

Expected behavior

I would expect no UserWarning for something related to Setuptools while scanning code with Pylint.

While I think that this is mostly a toxic interaction between Setuptools and Pip imports, Pylint (or Astroid) could suppress these warnings by wrapping the imports needed for AST parsing with the warnings.catch_warnings context manager or something along those lines.

Pylint version

pylint --version
pylint 2.15.7
astroid 2.12.13
Python 3.7.15 (default, Oct 15 2022, 11:29:20)
[GCC 9.4.0]

OS / Environment

No response

Additional dependencies

No response

@emcd emcd added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Dec 7, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component Needs astroid update Needs an astroid update (probably a release too) before being mergable 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 Dec 7, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.17.3 milestone Apr 16, 2023
@jacobtylerwalls jacobtylerwalls removed the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants