cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Regression: importlib.metadata.PathDistribution.requires raises AttributeError, name/version raises TypeError

Open hroncok opened this issue 2 weeks ago • 5 comments

Bug report

Bug description:

Python 3.14.2

>>> from importlib import metadata
>>> d = metadata.PathDistribution.at('/tmp')
>>> d.requires
>>> d.requires is None
True

Python 3.15.0a3

>>> from importlib import metadata
>>> d = metadata.PathDistribution.at('/tmp')
>>> d.requires
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    d.requires
  File "/usr/lib64/python3.15/importlib/metadata/__init__.py", line 660, in requires
    reqs = self._read_dist_info_reqs() or self._read_egg_info_reqs()
           ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib64/python3.15/importlib/metadata/__init__.py", line 664, in _read_dist_info_reqs
    return self.metadata.get_all('Requires-Dist')
           ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_all'

I believe this is a regression from 9b38c6698a3d6e7b37279dd9ae0d4d6430f9c612 where the metadata property changed the type from _meta.PackageMetadata to _meta.PackageMetadata | None but other properties (here the requires property) do not account for it being None.

This was discovered as a failure of tests of rpmlint in Fedora's continuous testing of Python pre-releases: https://bugzilla.redhat.com/show_bug.cgi?id=2424585

CPython versions tested on:

3.15

Operating systems tested on:

Linux

hroncok avatar Jan 03 '26 11:01 hroncok