D7701: resourceutil: use `from importlib import resources`
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Thu Dec 19 00:45:57 EST 2019
martinvonz updated this revision to Diff 18871.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D7701?vs=18868&id=18871
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D7701/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D7701
AFFECTED FILES
mercurial/utils/resourceutil.py
CHANGE DETAILS
diff --git a/mercurial/utils/resourceutil.py b/mercurial/utils/resourceutil.py
--- a/mercurial/utils/resourceutil.py
+++ b/mercurial/utils/resourceutil.py
@@ -37,19 +37,19 @@
datapath = os.path.dirname(os.path.dirname(pycompat.fsencode(__file__)))
try:
- import importlib
+ from importlib import resources
# Force loading of the resources module
- importlib.resources.open_binary # pytype: disable=module-attr
+ resources.open_binary # pytype: disable=module-attr
def open_resource(package, name):
package = b'mercurial.' + package
- return importlib.resources.open_binary( # pytype: disable=module-attr
+ return resources.open_binary( # pytype: disable=module-attr
pycompat.sysstr(package), pycompat.sysstr(name)
)
-except AttributeError:
+except (ImportError, AttributeError):
def _package_path(package):
return os.path.join(datapath, *package.split(b'.'))
To: martinvonz, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel
More information about the Mercurial-devel
mailing list