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

importlib.metadata.version(None) returns arbitrary version number #93259

Open
peterzahemszky opened this issue May 26, 2022 · 1 comment
Open

importlib.metadata.version(None) returns arbitrary version number #93259

peterzahemszky opened this issue May 26, 2022 · 1 comment
Labels
type-bug

Comments

@peterzahemszky
Copy link

@peterzahemszky peterzahemszky commented May 26, 2022

The version() function of the importlib.metadata package returns an arbitrary version number when called with None. There's no documentation on what the return value means.

I would have expected one of the following instead:

  • raise an error saying that the distribution_name parameter cannot be None, or
  • explain what the return value means in the relevant documentation.

The current behaviour is confusing as one could think, for example, that the return value is the version of the project/package they call it from.

>>> import sys
>>> print(sys.version)
3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]
>>> import importlib.metadata
>>> importlib.metadata.version(None)
'21.2.3'

I looks like the return value is the version of an arbitrary package installed in the Python virtual environment. Calling the function repeatedly seems to give the same value, but installing a new package can cause the return value to change.

System information

  • CPython versions tested on: 3.10.0
  • Operating system and architecture: Windows 10 Enterprise (64-bit operating system, x64-based processor)
@peterzahemszky peterzahemszky added the type-bug label May 26, 2022
@warsaw
Copy link
Member

@warsaw warsaw commented May 26, 2022

I can't think of a valid meaning for distribution_name=None in this or any related API. In a fresh checkout of CPython main, you do get an exception, but probably not the right one. It should probably quick raise a ValueError.

@jaraco

Python 3.12.0a0 (heads/main:da39719483, May 26 2022, 09:01:35) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib.metadata import version
>>> version(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/barry/projects/python/cpython/Lib/importlib/metadata/__init__.py", line 991, in version
    return distribution(distribution_name).version
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/barry/projects/python/cpython/Lib/importlib/metadata/__init__.py", line 964, in distribution
    return Distribution.from_name(distribution_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/barry/projects/python/cpython/Lib/importlib/metadata/__init__.py", line 561, in from_name
    raise PackageNotFoundError(name)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
importlib.metadata.PackageNotFoundError: No package metadata was found for None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug
Projects
None yet
Development

No branches or pull requests

2 participants