Avoid deprecated importlib.abc.TraversableResources (#81082)

* Avoid usage of deprecated importlib.abc.TraversableResources

This fixes ansible-compat test failures with Python 3.12.

* 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>
pull/79518/merge
Maxwell G 1 year ago committed by GitHub
parent c69951daca
commit bd5b0b4293
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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).

@ -40,8 +40,19 @@ except ImportError:
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.
from importlib.abc import TraversableResources # deprecated: description='TraversableResources move' python_version='3.10'
except ImportError:
# Python < 3.9
# deprecated: description='TraversableResources fallback' python_version='3.8'
TraversableResources = object # type: ignore[assignment,misc]
try:

Loading…
Cancel
Save