# HG changeset patch # User Matt Harbison # Date 1616125260 14400 # Node ID 2c0e35f6957abab074d2a96ab4e1dbc58349b3e2 # Parent 9ff4672c8c26df3f7134d738cd771a7e35b85aac typing: mark the argument to mercurial.i18n.gettext() non-Optional 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 @overloads. 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. Differential Revision: https://phab.mercurial-scm.org/D10235 diff -r 9ff4672c8c26 -r 2c0e35f6957a mercurial/i18n.py --- a/mercurial/i18n.py Thu Mar 18 18:57:21 2021 -0400 +++ b/mercurial/i18n.py Thu Mar 18 23:41:00 2021 -0400 @@ -23,7 +23,6 @@ from typing import ( Callable, List, - Optional, ) @@ -71,7 +70,7 @@ def gettext(message): - # type: (Optional[bytes]) -> Optional[bytes] + # type: (bytes) -> bytes """Translate message. The message is looked up in the catalog to get a Unicode string,