-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add '_compat.repair_extras' to repair extras from older, broken impor…
…tlib metadata implementations.
- Loading branch information
Showing
3 changed files
with
23 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
if False: | ||
# bugfix from 4.11.2 is required | ||
import contextlib | ||
|
||
|
||
try: | ||
import importlib.metadata as metadata | ||
else: | ||
except ImportError: | ||
import importlib_metadata as metadata # type: ignore # noqa: F401 | ||
|
||
|
||
def repair_extras(extras): | ||
""" | ||
Repair extras that appear as match objects. | ||
python/importlib_metadata#369 revealed a flaw in the EntryPoint | ||
implementation. This function wraps the extras to ensure | ||
they are proper strings even on older implementations. | ||
""" | ||
with contextlib.suppress(AttributeError): | ||
return list(item.group(0) for item in extras) | ||
return extras |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters