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.
| pulkit | 
| hg-reviewers | 
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.
| Automatic diff as part of commit; lint not applicable. | 
| Automatic diff as part of commit; unit tests not applicable. | 
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/hgweb/server.py (7 lines) | |||
| M | tests/test-check-pyflakes.t (1 line) | 
| # hgweb/server.py - The standalone hg web server. | # hgweb/server.py - The standalone hg web server. | ||||
| # | # | ||||
| # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> | ||||
| # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | ||||
| # | # | ||||
| # This software may be used and distributed according to the terms of the | # This software may be used and distributed according to the terms of the | ||||
| # GNU General Public License version 2 or any later version. | # GNU General Public License version 2 or any later version. | ||||
| from __future__ import absolute_import | from __future__ import absolute_import | ||||
| import errno | import errno | ||||
| import importlib | |||||
| import os | import os | ||||
| import socket | import socket | ||||
| import sys | import sys | ||||
| import traceback | import traceback | ||||
| import wsgiref.validate | import wsgiref.validate | ||||
| from ..i18n import _ | from ..i18n import _ | ||||
| mimetypes.init() | mimetypes.init() | ||||
| except UnicodeDecodeError: | except UnicodeDecodeError: | ||||
| # Python 2.x's mimetypes module attempts to decode strings | # Python 2.x's mimetypes module attempts to decode strings | ||||
| # from Windows' ANSI APIs as ascii (fail), then re-encode them | # from Windows' ANSI APIs as ascii (fail), then re-encode them | ||||
| # as ascii (clown fail), because the default Python Unicode | # as ascii (clown fail), because the default Python Unicode | ||||
| # codec is hardcoded as ascii. | # codec is hardcoded as ascii. | ||||
| sys.argv # unwrap demand-loader so that reload() works | 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() | oldenc = sys.getdefaultencoding() | ||||
| sys.setdefaultencoding("latin1") # or any full 8-bit encoding | sys.setdefaultencoding("latin1") # or any full 8-bit encoding | ||||
| mimetypes.init() | mimetypes.init() | ||||
| sys.setdefaultencoding(oldenc) | sys.setdefaultencoding(oldenc) | ||||
| address = ui.config('web', 'address') | address = ui.config('web', 'address') | ||||
| port = util.getport(ui.config('web', 'port')) | port = util.getport(ui.config('web', 'port')) | ||||
| try: | try: | ||||
| return cls(ui, app, (address, port), handler) | return cls(ui, app, (address, port), handler) | ||||
| except socket.error as inst: | except socket.error as inst: | ||||
| raise error.Abort(_("cannot start server at '%s:%d': %s") | raise error.Abort(_("cannot start server at '%s:%d': %s") | ||||
| % (address, port, encoding.strtolocal(inst.args[1]))) | % (address, port, encoding.strtolocal(inst.args[1]))) | ||||
| > -X hgext/fsmonitor/pywatchman \ | > -X hgext/fsmonitor/pywatchman \ | ||||
| > -X mercurial/pycompat.py -X contrib/python-zstandard \ | > -X mercurial/pycompat.py -X contrib/python-zstandard \ | ||||
| > -X mercurial/thirdparty/cbor \ | > -X mercurial/thirdparty/cbor \ | ||||
| > -X mercurial/thirdparty/concurrent \ | > -X mercurial/thirdparty/concurrent \ | ||||
| > -X mercurial/thirdparty/zope \ | > -X mercurial/thirdparty/zope \ | ||||
| > 2>/dev/null \ | > 2>/dev/null \ | ||||
| > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py" | > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py" | ||||
| contrib/perf.py:*: undefined name 'xrange' (glob) (?) | contrib/perf.py:*: undefined name 'xrange' (glob) (?) | ||||
| mercurial/hgweb/server.py:*: undefined name 'reload' (glob) (?) | |||||