# HG changeset patch # User Matt Harbison # Date 2022-12-12 19:10:12 # Node ID de284a0b5614789f107dfa6364175d4f97440f8b # Parent a51328ba33ca10b46395c7a711d28f3bd33d0624 typing: add type hints to the prompt methods in mercurial/ui.py The @overloads allow for the callers that pass a non-None `default` to not have to worry about handling a None return to appease pytype. diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -31,6 +31,7 @@ from typing import ( TypeVar, Union, cast, + overload, ) from .i18n import _ @@ -1780,12 +1781,36 @@ class ui: return line + if pycompat.TYPE_CHECKING: + + @overload + def prompt(self, msg: bytes, default: bytes) -> bytes: + pass + + @overload + def prompt(self, msg: bytes, default: None) -> Optional[bytes]: + pass + def prompt(self, msg, default=b"y"): """Prompt user with msg, read response. If ui is not interactive, the default is returned. """ return self._prompt(msg, default=default) + if pycompat.TYPE_CHECKING: + + @overload + def _prompt( + self, msg: bytes, default: bytes, **opts: _MsgOpts + ) -> bytes: + pass + + @overload + def _prompt( + self, msg: bytes, default: None, **opts: _MsgOpts + ) -> Optional[bytes]: + pass + def _prompt(self, msg, default=b'y', **opts): opts = {**opts, 'default': default} if not self.interactive():