This is an archive of the discontinued Mercurial Phabricator instance.

typing: mark the argument to mercurial.i18n.gettext() non-Optional

Authored by mharbison72 on Mar 19 2021, 1:58 AM.



Few if any of the callers are handling a None return, which is making pytype
complain. I tried adding @overload definitions to indicate the bytes -> bytes
and None -> None relationship, but pytype doesn't seem to apply that to _()
through the function assignment. What did work was to change _() into its own
function that called gettext(), but that has an extra function call overhead.
Even putting that function into an if pycompat.TYPE_CHECKING block and leaving
the existing assignments in the else block caused pytype to lose track of the

At that point, I simply gave up. PyCharm doesn't like that it can return None,
given the new type hints, but pytype doesn't complain about this nor does it
see any callers passing None. The most important thing here is to catch str
being passed anyway.

Diff Detail

rHG Mercurial
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.