narrow: hoist a variable to a higher level to avoid use-before-init warning
In practice, this shouldn't generate an IOError, so there wouldn't have been a
problem. But PyCharm didn't know that.
To run the tests, do:
cd tests/
python run-tests.py
See https://mercurial-scm.org/wiki/WritingTests for
more information on writing tests.