##// END OF EJS Templates
typing: add type hints to argument checking functions in cmdutil...
Matt Harbison -
r50987:ce60c8d4 default
parent child Browse files
Show More
@@ -11,6 +11,15 b' import errno'
11 11 import os
12 12 import re
13 13
14 from typing import (
15 Any,
16 AnyStr,
17 Dict,
18 Iterable,
19 Optional,
20 cast,
21 )
22
14 23 from .i18n import _
15 24 from .node import (
16 25 hex,
@@ -64,14 +73,10 b' from .revlogutils import ('
64 73 )
65 74
66 75 if pycompat.TYPE_CHECKING:
67 from typing import (
68 Any,
69 Dict,
76 from . import (
77 ui as uimod,
70 78 )
71 79
72 for t in (Any, Dict):
73 assert t
74
75 80 stringio = util.stringio
76 81
77 82 # templates of common command options
@@ -268,13 +273,16 b' debugrevlogopts = ['
268 273 _linebelow = b"^HG: ------------------------ >8 ------------------------$"
269 274
270 275
271 def check_at_most_one_arg(opts, *args):
276 def check_at_most_one_arg(
277 opts: Dict[AnyStr, Any],
278 *args: AnyStr,
279 ) -> Optional[AnyStr]:
272 280 """abort if more than one of the arguments are in opts
273 281
274 282 Returns the unique argument or None if none of them were specified.
275 283 """
276 284
277 def to_display(name):
285 def to_display(name: AnyStr) -> bytes:
278 286 return pycompat.sysbytes(name).replace(b'_', b'-')
279 287
280 288 previous = None
@@ -289,7 +297,11 b' def check_at_most_one_arg(opts, *args):'
289 297 return previous
290 298
291 299
292 def check_incompatible_arguments(opts, first, others):
300 def check_incompatible_arguments(
301 opts: Dict[AnyStr, Any],
302 first: AnyStr,
303 others: Iterable[AnyStr],
304 ) -> None:
293 305 """abort if the first argument is given along with any of the others
294 306
295 307 Unlike check_at_most_one_arg(), `others` are not mutually exclusive
@@ -299,7 +311,7 b' def check_incompatible_arguments(opts, f'
299 311 check_at_most_one_arg(opts, first, other)
300 312
301 313
302 def resolve_commit_options(ui, opts):
314 def resolve_commit_options(ui: "uimod.ui", opts: Dict[str, Any]) -> bool:
303 315 """modify commit options dict to handle related options
304 316
305 317 The return value indicates that ``rewrite.update-timestamp`` is the reason
@@ -326,7 +338,7 b' def resolve_commit_options(ui, opts):'
326 338 return datemaydiffer
327 339
328 340
329 def check_note_size(opts):
341 def check_note_size(opts: Dict[str, Any]) -> None:
330 342 """make sure note is of valid format"""
331 343
332 344 note = opts.get('note')
@@ -1114,12 +1126,12 b' def bailifchanged(repo, merge=True, hint'
1114 1126 ctx.sub(s).bailifchanged(hint=hint)
1115 1127
1116 1128
1117 def logmessage(ui, opts):
1129 def logmessage(ui: "uimod.ui", opts: Dict[bytes, Any]) -> Optional[bytes]:
1118 1130 """get the log message according to -m and -l option"""
1119 1131
1120 1132 check_at_most_one_arg(opts, b'message', b'logfile')
1121 1133
1122 message = opts.get(b'message')
1134 message = cast(Optional[bytes], opts.get(b'message'))
1123 1135 logfile = opts.get(b'logfile')
1124 1136
1125 1137 if not message and logfile:
@@ -1464,7 +1476,7 b' def openrevlog(repo, cmd, file_, opts):'
1464 1476 return openstorage(repo, cmd, file_, opts, returnrevlog=True)
1465 1477
1466 1478
1467 def copy(ui, repo, pats, opts, rename=False):
1479 def copy(ui, repo, pats, opts: Dict[bytes, Any], rename=False):
1468 1480 check_incompatible_arguments(opts, b'forget', [b'dry_run'])
1469 1481
1470 1482 # called with the repo lock held
@@ -2777,7 +2789,7 b' def cat(ui, repo, ctx, matcher, basefm, '
2777 2789 basefm,
2778 2790 fntemplate,
2779 2791 subprefix,
2780 **pycompat.strkwargs(opts)
2792 **pycompat.strkwargs(opts),
2781 2793 ):
2782 2794 err = 0
2783 2795 except error.RepoLookupError:
@@ -2931,7 +2943,7 b' def samefile(f, ctx1, ctx2):'
2931 2943 return f not in ctx2.manifest()
2932 2944
2933 2945
2934 def amend(ui, repo, old, extra, pats, opts):
2946 def amend(ui, repo, old, extra, pats, opts: Dict[str, Any]):
2935 2947 # avoid cycle context -> subrepo -> cmdutil
2936 2948 from . import context
2937 2949
General Comments 0
You need to be logged in to leave comments. Login now