Skip to content

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

@emcd

Description

@emcd

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement ✨Improvement to a componentNeeds astroid updateNeeds an astroid update (probably a release too) before being mergable

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions