Mercurial > public > mercurial-scm > hg
comparison mercurial/utils/urlutil.py @ 51666:a09435c0eb14
typing: add a few type hints to `mercurial/utils/urlutil.py`
Somewhere between hg 3dbc7b1ecaba and hg 8e3f6b5bf720, `_pathsuboptions` changed
from `Dict[bytes, Tuple[bytes, Any]]` to `Dict[bytes, Tuple[str, Any]]`, and it
caught my attention from diffing the local *.pyi files. The change is correct
based on the assertion, so let's get pytype to check for this instead of relying
on the assertion alone.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 10 Jul 2024 16:04:53 -0400 |
parents | f15cb5111a1e |
children | 1c5810ce737e |
comparison
equal
deleted
inserted
replaced
51665:32a1c9226dd9 | 51666:a09435c0eb14 |
---|---|
7 import os | 7 import os |
8 import re as remod | 8 import re as remod |
9 import socket | 9 import socket |
10 | 10 |
11 from typing import ( | 11 from typing import ( |
12 Callable, | |
13 Dict, | |
14 Tuple, | |
12 Union, | 15 Union, |
13 ) | 16 ) |
14 | 17 |
15 from ..i18n import _ | 18 from ..i18n import _ |
16 from .. import ( | 19 from .. import ( |
27 from ..revlogutils import ( | 30 from ..revlogutils import ( |
28 constants as revlog_constants, | 31 constants as revlog_constants, |
29 ) | 32 ) |
30 | 33 |
31 # keeps pyflakes happy | 34 # keeps pyflakes happy |
32 assert [Union] | 35 assert [Callable, Dict, Tuple, Union] |
33 | 36 |
34 urlreq = urllibcompat.urlreq | 37 urlreq = urllibcompat.urlreq |
35 | 38 |
36 | 39 |
37 def getport(port: Union[bytes, int]) -> int: | 40 def getport(port: Union[bytes, int]) -> int: |
650 for p in old_paths: | 653 for p in old_paths: |
651 new_paths.extend(_chain_path(p, ui, self)) | 654 new_paths.extend(_chain_path(p, ui, self)) |
652 self[name] = new_paths | 655 self[name] = new_paths |
653 | 656 |
654 | 657 |
655 _pathsuboptions = {} | 658 _pathsuboptions: "Dict[bytes, Tuple[str, Callable]]" = {} |
656 # a dictionnary of methods that can be used to format a sub-option value | 659 # a dictionnary of methods that can be used to format a sub-option value |
657 path_suboptions_display = {} | 660 path_suboptions_display = {} |
658 | 661 |
659 | 662 |
660 def pathsuboption(option, attr, display=pycompat.bytestr): | 663 def pathsuboption(option: bytes, attr: str, display=pycompat.bytestr): |
661 """Decorator used to declare a path sub-option. | 664 """Decorator used to declare a path sub-option. |
662 | 665 |
663 Arguments are the sub-option name and the attribute it should set on | 666 Arguments are the sub-option name and the attribute it should set on |
664 ``path`` instances. | 667 ``path`` instances. |
665 | 668 |