2023-06-22 20:11:14 +00:00
|
|
|
From bd5b0b4293f454819766437cb6f8a7037affd49e Mon Sep 17 00:00:00 2001
|
2023-06-17 18:07:21 +00:00
|
|
|
From: Maxwell G <maxwell@gtmx.me>
|
2023-06-22 20:11:14 +00:00
|
|
|
Date: Tue, 20 Jun 2023 13:54:06 -0500
|
|
|
|
Subject: [PATCH] Avoid deprecated importlib.abc.TraversableResources (#81082)
|
|
|
|
|
|
|
|
* Avoid usage of deprecated importlib.abc.TraversableResources
|
2023-06-17 18:07:21 +00:00
|
|
|
|
|
|
|
This fixes ansible-compat test failures with Python 3.12.
|
2023-06-22 20:11:14 +00:00
|
|
|
|
|
|
|
* Add deprecated: marker for compat code
|
|
|
|
|
|
|
|
Co-authored-by: Matt Davis <6775756+nitzmahone@users.noreply.github.com>
|
|
|
|
|
|
|
|
* add declarative deprecation comment to < 3.9 case
|
|
|
|
|
|
|
|
Co-authored-by: Matt Clay <matt@mystile.com>
|
|
|
|
|
|
|
|
---------
|
|
|
|
|
|
|
|
Co-authored-by: Matt Davis <6775756+nitzmahone@users.noreply.github.com>
|
|
|
|
Co-authored-by: Matt Clay <matt@mystile.com>
|
2023-06-17 18:07:21 +00:00
|
|
|
---
|
2023-06-22 20:11:14 +00:00
|
|
|
.../fragments/81082-deprecated-importlib-abc.yml | 5 +++++
|
|
|
|
.../utils/collection_loader/_collection_finder.py | 13 ++++++++++++-
|
|
|
|
2 files changed, 17 insertions(+), 1 deletion(-)
|
2023-06-17 18:07:21 +00:00
|
|
|
create mode 100644 changelogs/fragments/81082-deprecated-importlib-abc.yml
|
|
|
|
|
|
|
|
diff --git a/changelogs/fragments/81082-deprecated-importlib-abc.yml b/changelogs/fragments/81082-deprecated-importlib-abc.yml
|
|
|
|
new file mode 100644
|
|
|
|
index 00000000000000..6dfd90a16bed66
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/changelogs/fragments/81082-deprecated-importlib-abc.yml
|
|
|
|
@@ -0,0 +1,5 @@
|
|
|
|
+---
|
|
|
|
+minor_changes:
|
|
|
|
+ - Use ``importlib.resources.abc.TraversableResources`` instead of deprecated
|
|
|
|
+ ``importlib.abc.TraversableResources`` where available
|
|
|
|
+ (https:/github.com/ansible/ansible/pull/81082).
|
|
|
|
diff --git a/lib/ansible/utils/collection_loader/_collection_finder.py b/lib/ansible/utils/collection_loader/_collection_finder.py
|
2023-06-22 20:11:14 +00:00
|
|
|
index fc6744ffdef64e..16d0bcc6e8e92a 100644
|
2023-06-17 18:07:21 +00:00
|
|
|
--- a/lib/ansible/utils/collection_loader/_collection_finder.py
|
|
|
|
+++ b/lib/ansible/utils/collection_loader/_collection_finder.py
|
2023-06-22 20:11:14 +00:00
|
|
|
@@ -40,8 +40,19 @@ def import_module(name): # type: ignore[misc]
|
2023-06-17 18:07:21 +00:00
|
|
|
reload_module = reload # type: ignore[name-defined] # pylint:disable=undefined-variable
|
|
|
|
|
|
|
|
try:
|
|
|
|
- from importlib.abc import TraversableResources
|
|
|
|
+ try:
|
|
|
|
+ # Available on Python >= 3.11
|
|
|
|
+ # We ignore the import error that will trigger when running mypy with
|
|
|
|
+ # older Python versions.
|
|
|
|
+ from importlib.resources.abc import TraversableResources # type: ignore[import]
|
|
|
|
+ except ImportError:
|
|
|
|
+ # Used with Python 3.9 and 3.10 only
|
|
|
|
+ # This member is still available as an alias up until Python 3.14 but
|
|
|
|
+ # is deprecated as of Python 3.12.
|
2023-06-22 20:11:14 +00:00
|
|
|
+ from importlib.abc import TraversableResources # deprecated: description='TraversableResources move' python_version='3.10'
|
2023-06-17 18:07:21 +00:00
|
|
|
except ImportError:
|
|
|
|
+ # Python < 3.9
|
2023-06-22 20:11:14 +00:00
|
|
|
+ # deprecated: description='TraversableResources fallback' python_version='3.8'
|
2023-06-17 18:07:21 +00:00
|
|
|
TraversableResources = object # type: ignore[assignment,misc]
|
|
|
|
|
|
|
|
try:
|