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

BUG: [py3.11] AttributeError: 'PathDistribution' object has no attribute '_normalized_name' #98706

Closed
h-vetinari opened this issue Oct 26, 2022 · 4 comments
Assignees
Labels
topic-importlib type-bug An unexpected behavior, bug, or error

Comments

@h-vetinari
Copy link

This shows up while trying to run the numpy test suite with python 3.11 and the newest pytest etc.

==================================== ERRORS ====================================
________________________ ERROR collecting test session _________________________

[...]

=========================== short test summary info ============================
ERROR  - AttributeError: 'PathDistribution' object has no attribute '_normalized_name'
ERROR  - AttributeError: 'PathDistribution' object has no attribute '_normalized_name'
2 errors in 1.41s

More precisely, the error appears in the vendored import_lib module

[...]/lib/python3.11/importlib/metadata/__init__.py:472: in load
    ordered = sorted(eps, key=by_group)
        by_group   = operator.attrgetter('group')
        cls        = <class 'importlib.metadata.SelectableGroups'>
        eps        = <itertools.chain object at 0x7f19804ea5f0>
[...]/lib/python3.11/importlib/metadata/__init__.py:1013: in <genexpr>
    eps = itertools.chain.from_iterable(
        .0         = <generator object unique_everseen at 0x7f19805e9d40>
[...]/lib/python3.11/importlib/metadata/_itertools.py:16: in unique_everseen
    k = key(element)
E   AttributeError: 'PathDistribution' object has no attribute '_normalized_name'
        element    = <importlib_metadata.PathDistribution object at 0x7f19802c0450>
        iterable   = <itertools.chain object at 0x7f19804eae00>
        key        = operator.attrgetter('_normalized_name')
        seen       = set()
        seen_add   = <built-in method add of set object at 0x7f198035b060>

Turns out this is python/importlib_metadata#396 (fixed in 4.13.0), where @jaraco noted:

Perhaps importlib_metadata should provide a compatibility shim to honor name normalization in distributions not supplying it (or at least not crash).

Unfortunately, the vendored version present in python 3.11 is only at 4.11.3, hence does not carry the fix.

@h-vetinari h-vetinari added the type-bug An unexpected behavior, bug, or error label Oct 26, 2022
@h-vetinari
Copy link
Author

In the meantime, a work-around is to install importlib_metadata >=4.13.

@jaraco
Copy link
Member

jaraco commented Oct 30, 2022

It looks like applying python/importlib_metadata@3e52430 should do the trick. Because #97785 is already in main, the changes will need to be applied to the 3.11 branch directly.

@jaraco
Copy link
Member

jaraco commented Oct 30, 2022

I note that 4.12.0 also includes changes that I'd previously not backported to Python 3.11 (#94270). @pablogsal Are you okay with changes from importlib_metadata 4.11.4-4.13.0 being applied as a bugfix for Python 3.11?

@jaraco
Copy link
Member

jaraco commented Oct 30, 2022

I've applied the changes to the 3.11 branch with:

 cpython 3.11 $ http --follow https://github.com/python/importlib_metadata/archive/3e52430a4a4cec3ac06ab78ff6909a9c3ac62426.zip | bsdtar -x --strip-components 1

jaraco added a commit to jaraco/cpython that referenced this issue Oct 30, 2022
miss-islington pushed a commit that referenced this issue Nov 5, 2022
These changes are already applied to main but have been selected from importlib_metadata 4.x for their bug fixes.
@jaraco jaraco closed this as completed Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-importlib type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants