Skip to content

[BUG] Setuptools overriding standard lib importlib.metadata.PathDistribution #3169

@tlambert03

Description

@tlambert03

setuptools version

60.9.3

Python version

python 3.9

OS

macOS

Additional environment information

❯ pip list
Package    Version
---------- -------
pip        22.0.4
setuptools 60.9.3
wheel      0.37.1

Description

this seems similar to #3102, but issue was closed by #3108, without activity since then, and I still seeing this issue in the latest release.

importing setuptools overrides/removes the behavior and return type of of the standard library importlib.metadata.distribution() function:

Expected behavior

importing setuptools doesn't supersede/remove the distribution finder from standard library importlib

How to Reproduce

  1. import setuptools
  2. call importlib.metadata.distribution()

Output

>>> from importlib import metadata
>>> metadata.distribution('pip')  # returns the expected type
<importlib.metadata.PathDistribution object at 0x101665910>
>>> import sys
>>> [getattr(finder, 'find_distributions', None) for finder in sys.meta_path]
[None, None, None, <bound method PathFinder.find_distributions of <class '_frozen_importlib_external.PathFinder'>>]

# importing setuptools changes the type of object returned by metadata.distribution
# and removes the _frozen_importlib_external.PathFinder from 
# the list of finders used by `metadata.Distribution.discover`
>>> import setuptools
>>> metadata.distribution('pip')
<setuptools._vendor.importlib_metadata.PathDistribution object at 0x102253070>
>>> [getattr(finder, 'find_distributions', None) for finder in sys.meta_path]
[None, None, None, None, None, None, <bound method MetadataPathFinder.find_distributions of <setuptools._vendor.importlib_metadata.MetadataPathFinder object at 0x101fdad00>>]

# note:
>>> import importlib_metadata
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'importlib_metadata'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TriageIssues that need to be evaluated for severity and status.bug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions