Mercurial > hg
changeset 43069:e554cfd93975
hgweb: use importlib.reload() if available
reload() was nuked in Python 3. We need to use importlib.reload()
instead.
But pyflakes isn't smart enough to detect our conditional usage, so
we allow this error.
Differential Revision: https://phab.mercurial-scm.org/D6992
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 05 Oct 2019 17:44:54 -0400 |
parents | 094d0f4a8edd |
children | 1d60a7825dcb |
files | mercurial/hgweb/server.py tests/test-check-pyflakes.t |
diffstat | 2 files changed, 7 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/server.py Sat Oct 05 16:57:45 2019 -0400 +++ b/mercurial/hgweb/server.py Sat Oct 05 17:44:54 2019 -0400 @@ -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()
--- a/tests/test-check-pyflakes.t Sat Oct 05 16:57:45 2019 -0400 +++ b/tests/test-check-pyflakes.t Sat Oct 05 17:44:54 2019 -0400 @@ -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) (?)