Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/ui.py @ 49894: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 | dcf983a5f906 |
comparison
equal
deleted
inserted
replaced
49893:a51328ba33ca | 49894:de284a0b5614 |
---|---|
29 Tuple, | 29 Tuple, |
30 Type, | 30 Type, |
31 TypeVar, | 31 TypeVar, |
32 Union, | 32 Union, |
33 cast, | 33 cast, |
34 overload, | |
34 ) | 35 ) |
35 | 36 |
36 from .i18n import _ | 37 from .i18n import _ |
37 from .node import hex | 38 from .node import hex |
38 from .pycompat import ( | 39 from .pycompat import ( |
1778 raise EOFError | 1779 raise EOFError |
1779 line = line.rstrip(pycompat.oslinesep) | 1780 line = line.rstrip(pycompat.oslinesep) |
1780 | 1781 |
1781 return line | 1782 return line |
1782 | 1783 |
1784 if pycompat.TYPE_CHECKING: | |
1785 | |
1786 @overload | |
1787 def prompt(self, msg: bytes, default: bytes) -> bytes: | |
1788 pass | |
1789 | |
1790 @overload | |
1791 def prompt(self, msg: bytes, default: None) -> Optional[bytes]: | |
1792 pass | |
1793 | |
1783 def prompt(self, msg, default=b"y"): | 1794 def prompt(self, msg, default=b"y"): |
1784 """Prompt user with msg, read response. | 1795 """Prompt user with msg, read response. |
1785 If ui is not interactive, the default is returned. | 1796 If ui is not interactive, the default is returned. |
1786 """ | 1797 """ |
1787 return self._prompt(msg, default=default) | 1798 return self._prompt(msg, default=default) |
1799 | |
1800 if pycompat.TYPE_CHECKING: | |
1801 | |
1802 @overload | |
1803 def _prompt( | |
1804 self, msg: bytes, default: bytes, **opts: _MsgOpts | |
1805 ) -> bytes: | |
1806 pass | |
1807 | |
1808 @overload | |
1809 def _prompt( | |
1810 self, msg: bytes, default: None, **opts: _MsgOpts | |
1811 ) -> Optional[bytes]: | |
1812 pass | |
1788 | 1813 |
1789 def _prompt(self, msg, default=b'y', **opts): | 1814 def _prompt(self, msg, default=b'y', **opts): |
1790 opts = {**opts, 'default': default} | 1815 opts = {**opts, 'default': default} |
1791 if not self.interactive(): | 1816 if not self.interactive(): |
1792 self._writemsg(self._fmsgout, msg, b' ', type=b'prompt', **opts) | 1817 self._writemsg(self._fmsgout, msg, b' ', type=b'prompt', **opts) |