import-checker: resolve relative imports
"from . import X" will produce an ImportFrom ast node with .module =
None. This resulted in a run-time error from attempting to concatenate
None with a str.
Another problem with relative imports is that the prefix may be dynamic
based on the "level" attribute of the import. e.g. "from ." has level 1
and "from .." has level 2.
We teach the "fromlocal" function how to cope with relative imports.
Where appropriate, the consumer passes in the level so relative module
names may be resolved properly.
# A dummy extension that installs an hgweb command that throws an Exception.
from mercurial.hgweb import webcommands
def raiseerror(web, req, tmpl):
'''Dummy web command that raises an uncaught Exception.'''
# Simulate an error after partial response.
if 'partialresponse' in req.form:
req.respond(200, 'text/plain')
req.write('partial content\n')
raise AttributeError('I am an uncaught error!')
def extsetup(ui):
setattr(webcommands, 'raiseerror', raiseerror)
webcommands.__all__.append('raiseerror')