Mercurial > hg
changeset 49799:de284a0b5614
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.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 12 Dec 2022 14:10:12 -0500 |
parents | a51328ba33ca |
children | c43b283a19c3 |
files | mercurial/ui.py |
diffstat | 1 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/ui.py Mon Dec 12 14:17:05 2022 -0500 +++ b/mercurial/ui.py Mon Dec 12 14:10:12 2022 -0500 @@ -31,6 +31,7 @@ TypeVar, Union, cast, + overload, ) from .i18n import _ @@ -1780,12 +1781,36 @@ 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():