[Updated] D11312: resources: narrow the try:except clause to minimum
marmoute (Pierre-Yves David)
phabricator at mercurial-scm.org
Sun Aug 22 20:55:34 UTC 2021
Closed by commit rHG08f16b3331df: resources: narrow the try:except clause to minimum (authored by marmoute).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D11312?vs=29961&id=29985
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D11312/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D11312
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
@@ -59,28 +59,9 @@
# further down
from importlib import resources
- from .. import encoding
-
# Force loading of the resources module
resources.open_binary # pytype: disable=module-attr
- def open_resource(package, name):
- return resources.open_binary( # pytype: disable=module-attr
- pycompat.sysstr(package), pycompat.sysstr(name)
- )
-
- def is_resource(package, name):
- return resources.is_resource( # pytype: disable=module-attr
- pycompat.sysstr(package), encoding.strfromlocal(name)
- )
-
- def contents(package):
- # pytype: disable=module-attr
- for r in resources.contents(pycompat.sysstr(package)):
- # pytype: enable=module-attr
- yield encoding.strtolocal(r)
-
-
except (ImportError, AttributeError):
# importlib.resources was not found (almost definitely because we're on a
# Python version before 3.7)
@@ -102,3 +83,23 @@
for p in os.listdir(path):
yield pycompat.fsencode(p)
+
+
+else:
+ from .. import encoding
+
+ def open_resource(package, name):
+ return resources.open_binary( # pytype: disable=module-attr
+ pycompat.sysstr(package), pycompat.sysstr(name)
+ )
+
+ def is_resource(package, name):
+ return resources.is_resource( # pytype: disable=module-attr
+ pycompat.sysstr(package), encoding.strfromlocal(name)
+ )
+
+ def contents(package):
+ # pytype: disable=module-attr
+ for r in resources.contents(pycompat.sysstr(package)):
+ # pytype: enable=module-attr
+ yield encoding.strtolocal(r)
To: marmoute, #hg-reviewers
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210822/4a2f797c/attachment-0002.html>
More information about the Mercurial-patches
mailing list