D6992: hgweb: use importlib.reload() if available

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Sun Oct 6 11:06:00 EDT 2019


Closed by commit rHGe554cfd93975: hgweb: use importlib.reload() if available (authored by indygreg).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6992?vs=16864&id=16891

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6992/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6992

AFFECTED FILES
  mercurial/hgweb/server.py
  tests/test-check-pyflakes.t

CHANGE DETAILS

diff --git a/tests/test-check-pyflakes.t b/tests/test-check-pyflakes.t
--- a/tests/test-check-pyflakes.t
+++ b/tests/test-check-pyflakes.t
@@ -22,4 +22,5 @@
   > 2>/dev/null \
   > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
   contrib/perf.py:*: undefined name 'xrange' (glob) (?)
+  mercurial/hgweb/server.py:*: undefined name 'reload' (glob) (?)
   
diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -9,6 +9,7 @@
 from __future__ import absolute_import
 
 import errno
+import importlib
 import os
 import socket
 import sys
@@ -370,7 +371,11 @@
         # codec is hardcoded as ascii.
 
         sys.argv # unwrap demand-loader so that reload() works
-        reload(sys) # resurrect sys.setdefaultencoding()
+        # resurrect sys.setdefaultencoding()
+        try:
+            importlib.reload(sys)
+        except AttributeError:
+            reload(sys)
         oldenc = sys.getdefaultencoding()
         sys.setdefaultencoding("latin1") # or any full 8-bit encoding
         mimetypes.init()



To: indygreg, #hg-reviewers, pulkit
Cc: mercurial-devel


More information about the Mercurial-devel mailing list