##// END OF EJS Templates
pytype: import typing directly...
marmoute -
r52178:9d372155 default
parent child Browse files
Show More
@@ -13,47 +13,50 b' from .node import ('
13 13 hex,
14 14 nullrev,
15 15 )
16
17 from typing import (
18 Any,
19 Callable,
20 Dict,
21 Iterable,
22 List,
23 Optional,
24 Set,
25 TYPE_CHECKING,
26 Tuple,
27 Union,
28 )
29
16 30 from . import (
17 31 encoding,
18 32 error,
19 33 obsolete,
20 pycompat,
21 34 scmutil,
22 35 util,
23 36 )
37
24 38 from .utils import (
25 39 repoviewutil,
26 40 stringutil,
27 41 )
28 42
29 if pycompat.TYPE_CHECKING:
30 from typing import (
31 Any,
32 Callable,
33 Dict,
34 Iterable,
35 List,
36 Optional,
37 Set,
38 Tuple,
39 Union,
40 )
43 # keeps pyflakes happy
44 assert [
45 Any,
46 Callable,
47 Dict,
48 Iterable,
49 List,
50 Optional,
51 Set,
52 Tuple,
53 Union,
54 ]
55
56 if TYPE_CHECKING:
41 57 from . import localrepo
42 58
43 assert any(
44 (
45 Any,
46 Callable,
47 Dict,
48 Iterable,
49 List,
50 Optional,
51 Set,
52 Tuple,
53 Union,
54 localrepo,
55 )
56 )
59 assert [localrepo]
57 60
58 61 subsettable = repoviewutil.subsettable
59 62
@@ -18,6 +18,7 b' from typing import ('
18 18 Dict,
19 19 Iterable,
20 20 Optional,
21 TYPE_CHECKING,
21 22 cast,
22 23 )
23 24
@@ -71,7 +72,7 b' from .revlogutils import ('
71 72 constants as revlog_constants,
72 73 )
73 74
74 if pycompat.TYPE_CHECKING:
75 if TYPE_CHECKING:
75 76 from . import (
76 77 ui as uimod,
77 78 )
@@ -9,8 +9,19 b''
9 9 import locale
10 10 import os
11 11 import re
12 import typing
12 13 import unicodedata
13 14
15 from typing import (
16 Any,
17 Callable,
18 List,
19 Text,
20 Type,
21 TypeVar,
22 Union,
23 )
24
14 25 from . import (
15 26 error,
16 27 policy,
@@ -19,22 +30,11 b' from . import ('
19 30
20 31 from .pure import charencode as charencodepure
21 32
22 if pycompat.TYPE_CHECKING:
23 from typing import (
24 Any,
25 Callable,
26 List,
27 Text,
28 Type,
29 TypeVar,
30 Union,
31 )
33 # keep pyflakes happy
34 for t in (Any, Callable, List, Text, Type, Union):
35 assert t
32 36
33 # keep pyflakes happy
34 for t in (Any, Callable, List, Text, Type, Union):
35 assert t
36
37 _Tlocalstr = TypeVar('_Tlocalstr', bound='localstr')
37 _Tlocalstr = TypeVar('_Tlocalstr', bound='localstr')
38 38
39 39 charencode = policy.importmod('charencode')
40 40
@@ -131,7 +131,7 b' class localstr(bytes):'
131 131 s._utf8 = u
132 132 return s
133 133
134 if pycompat.TYPE_CHECKING:
134 if typing.TYPE_CHECKING:
135 135 # pseudo implementation to help pytype see localstr() constructor
136 136 def __init__(self, u, l):
137 137 # type: (bytes, bytes) -> None
@@ -14,19 +14,30 b' imports.'
14 14
15 15 import difflib
16 16
17 from typing import (
18 Any,
19 AnyStr,
20 Iterable,
21 List,
22 Optional,
23 Sequence,
24 Union,
25 )
26
17 27 # Do not import anything but pycompat here, please
18 28 from . import pycompat
19 29
20 if pycompat.TYPE_CHECKING:
21 from typing import (
22 Any,
23 AnyStr,
24 Iterable,
25 List,
26 Optional,
27 Sequence,
28 Union,
29 )
30
31 # keeps pyflakes happy
32 assert [
33 Any,
34 AnyStr,
35 Iterable,
36 List,
37 Optional,
38 Sequence,
39 Union,
40 ]
30 41
31 42
32 43 def _tobytes(exc):
@@ -11,18 +11,22 b' import locale'
11 11 import os
12 12 import sys
13 13
14 from typing import (
15 Callable,
16 List,
17 )
18
14 19 from .utils import resourceutil
15 20 from . import (
16 21 encoding,
17 22 pycompat,
18 23 )
19 24
20 if pycompat.TYPE_CHECKING:
21 from typing import (
22 Callable,
23 List,
24 )
25
25 # keeps pyflakes happy
26 assert [
27 Callable,
28 List,
29 ]
26 30
27 31 # modelled after templater.templatepath:
28 32 if getattr(sys, 'frozen', None) is not None:
@@ -10,6 +10,15 b' import itertools'
10 10 import os
11 11 import posixpath
12 12
13 from typing import (
14 Any,
15 Callable,
16 Dict,
17 Optional,
18 Sequence,
19 Tuple,
20 )
21
13 22 from .i18n import _
14 23 from .node import wdirrev
15 24
@@ -39,19 +48,19 b' from .utils import ('
39 48 stringutil,
40 49 )
41 50
51 # keeps pyflakes happy
52 assert [
53 Any,
54 Callable,
55 Dict,
56 Optional,
57 Sequence,
58 Tuple,
59 ]
42 60
43 if pycompat.TYPE_CHECKING:
44 from typing import (
45 Any,
46 Callable,
47 Dict,
48 Optional,
49 Sequence,
50 Tuple,
51 )
52
53 for t in (Any, Callable, Dict, Optional, Tuple):
54 assert t
61 # keep pyflakes happy
62 for t in (Any, Callable, Dict, Optional, Tuple):
63 assert t
55 64
56 65
57 66 def getlimit(opts):
@@ -18,6 +18,13 b' import smtplib'
18 18 import socket
19 19 import time
20 20
21 from typing import (
22 Any,
23 List,
24 Tuple,
25 Union,
26 )
27
21 28 from .i18n import _
22 29 from .pycompat import (
23 30 open,
@@ -35,11 +42,14 b' from .utils import ('
35 42 urlutil,
36 43 )
37 44
38 if pycompat.TYPE_CHECKING:
39 from typing import Any, List, Tuple, Union
40 45
41 # keep pyflakes happy
42 assert all((Any, List, Tuple, Union))
46 # keep pyflakes happy
47 assert [
48 Any,
49 List,
50 Tuple,
51 Union,
52 ]
43 53
44 54
45 55 class STARTTLS(smtplib.SMTP):
@@ -23,6 +23,14 b' from . import ('
23 23 rustdirs = policy.importrust('dirstate', 'Dirs')
24 24 parsers = policy.importmod('parsers')
25 25
26 # keeps pyflakes happy
27 assert [
28 Any,
29 Callable,
30 Iterator,
31 Optional,
32 ]
33
26 34
27 35 def _lowerclean(s):
28 36 # type: (bytes) -> bytes
@@ -102,6 +102,18 b' Note: old client behave as a publishing '
102 102
103 103
104 104 import struct
105 import typing
106
107 from typing import (
108 Any,
109 Callable,
110 Dict,
111 Iterable,
112 List,
113 Optional,
114 Set,
115 Tuple,
116 )
105 117
106 118 from .i18n import _
107 119 from .node import (
@@ -120,23 +132,29 b' from . import ('
120 132 util,
121 133 )
122 134
123 if pycompat.TYPE_CHECKING:
124 from typing import (
125 Any,
126 Callable,
127 Dict,
128 Iterable,
129 List,
130 Optional,
131 Set,
132 Tuple,
133 )
135 # keeps pyflakes happy
136 assert [
137 Any,
138 Callable,
139 Dict,
140 Iterable,
141 List,
142 Optional,
143 Set,
144 Tuple,
145 ]
146
147 Phaseroots = Dict[int, Set[bytes]]
148
149 if typing.TYPE_CHECKING:
134 150 from . import (
135 151 localrepo,
136 152 ui as uimod,
137 153 )
138 154
139 Phaseroots = Dict[int, Set[bytes]]
155 # keeps pyflakes happy
156 assert [uimod]
157
140 158 Phasedefaults = List[
141 159 Callable[[localrepo.localrepository, Phaseroots], Phaseroots]
142 160 ]
@@ -70,13 +70,6 b' rename = os.rename'
70 70 removedirs = os.removedirs
71 71
72 72 if typing.TYPE_CHECKING:
73 # Replace the various overloads that come along with aliasing stdlib methods
74 # with the narrow definition that we care about in the type checking phase
75 # only. This ensures that both Windows and POSIX see only the definition
76 # that is actually available.
77 #
78 # Note that if we check pycompat.TYPE_CHECKING here, it is always False, and
79 # the methods aren't replaced.
80 73
81 74 def normpath(path: bytes) -> bytes:
82 75 raise NotImplementedError
@@ -3,6 +3,7 b' import errno'
3 3 import fcntl
4 4 import os
5 5 import sys
6 import typing
6 7
7 8 from typing import (
8 9 List,
@@ -15,7 +16,7 b' from . import ('
15 16 util,
16 17 )
17 18
18 if pycompat.TYPE_CHECKING:
19 if typing.TYPE_CHECKING:
19 20 from . import ui as uimod
20 21
21 22 # BSD 'more' escapes ANSI color sequences by default. This can be disabled by
@@ -3,6 +3,7 b' import winreg # pytype: disable=import-'
3 3
4 4 from typing import (
5 5 List,
6 TYPE_CHECKING,
6 7 Tuple,
7 8 )
8 9
@@ -13,7 +14,7 b' from . import ('
13 14 win32,
14 15 )
15 16
16 if pycompat.TYPE_CHECKING:
17 if TYPE_CHECKING:
17 18 from . import ui as uimod
18 19
19 20 # MS-DOS 'more' is the only pager available by default on Windows.
@@ -20,23 +20,22 b' the data.'
20 20
21 21 import contextlib
22 22
23 from typing import (
24 Any,
25 Dict,
26 )
27
23 28 from .i18n import _
24 29
25 30 from . import (
26 31 error,
27 pycompat,
28 32 util,
29 33 )
30 34 from .utils import cborutil
31 35
32 if pycompat.TYPE_CHECKING:
33 from typing import (
34 Any,
35 Dict,
36 )
37
38 for t in (Any, Dict):
39 assert t
36 # keeps pyflakes happy
37 for t in (Any, Dict):
38 assert t
40 39
41 40
42 41 class cmdstate:
@@ -9,6 +9,16 b''
9 9 import os
10 10 import posixpath
11 11 import re
12 import typing
13
14 from typing import (
15 Any,
16 Dict,
17 List,
18 Optional,
19 Set,
20 Tuple,
21 )
12 22
13 23 from .i18n import _
14 24 from . import (
@@ -17,7 +27,6 b' from . import ('
17 27 filemerge,
18 28 pathutil,
19 29 phases,
20 pycompat,
21 30 util,
22 31 )
23 32 from .utils import (
@@ -25,17 +34,19 b' from .utils import ('
25 34 urlutil,
26 35 )
27 36
37 # keeps pyflakes happy
38 assert [
39 Any,
40 Dict,
41 List,
42 Optional,
43 Set,
44 Tuple,
45 ]
46
28 47 nullstate = (b'', b'', b'empty')
29 48
30 if pycompat.TYPE_CHECKING:
31 from typing import (
32 Any,
33 Dict,
34 List,
35 Optional,
36 Set,
37 Tuple,
38 )
49 if typing.TYPE_CHECKING:
39 50 from . import (
40 51 context,
41 52 localrepo,
@@ -45,7 +56,17 b' if pycompat.TYPE_CHECKING:'
45 56 ui as uimod,
46 57 )
47 58
48 Substate = Dict[bytes, Tuple[bytes, bytes, bytes]]
59 # keeps pyflakes happy
60 assert [
61 context,
62 localrepo,
63 matchmod,
64 scmutil,
65 subrepo,
66 uimod,
67 ]
68
69 Substate = Dict[bytes, Tuple[bytes, bytes, bytes]]
49 70
50 71
51 72 def state(ctx, ui):
@@ -18,6 +18,7 b' import socket'
18 18 import subprocess
19 19 import sys
20 20 import traceback
21 import typing
21 22
22 23 from typing import (
23 24 Any,
@@ -1766,7 +1767,7 b' class ui:'
1766 1767
1767 1768 return line
1768 1769
1769 if pycompat.TYPE_CHECKING:
1770 if typing.TYPE_CHECKING:
1770 1771
1771 1772 @overload
1772 1773 def prompt(self, msg: bytes, default: bytes) -> bytes:
@@ -1782,7 +1783,7 b' class ui:'
1782 1783 """
1783 1784 return self._prompt(msg, default=default)
1784 1785
1785 if pycompat.TYPE_CHECKING:
1786 if typing.TYPE_CHECKING:
1786 1787
1787 1788 @overload
1788 1789 def _prompt(
@@ -7,11 +7,15 b''
7 7
8 8 import random
9 9
10 from typing import (
11 List,
12 Type,
13 )
14
10 15 from ..i18n import _
11 16 from .. import (
12 17 error,
13 18 localrepo,
14 pycompat,
15 19 requirements,
16 20 revlog,
17 21 util,
@@ -19,12 +23,11 b' from .. import ('
19 23
20 24 from ..utils import compression
21 25
22 if pycompat.TYPE_CHECKING:
23 from typing import (
24 List,
25 Type,
26 )
27
26 # keeps pyflakes happy
27 assert [
28 List,
29 Type,
30 ]
28 31
29 32 # list of requirements that request a clone of all revlog if added/removed
30 33 RECLONES_REQUIREMENTS = {
@@ -34,6 +34,14 b' import time'
34 34 import traceback
35 35 import warnings
36 36
37 from typing import (
38 Iterable,
39 Iterator,
40 List,
41 Optional,
42 Tuple,
43 )
44
37 45 from .node import hex
38 46 from .thirdparty import attr
39 47 from .pycompat import (
@@ -55,14 +63,14 b' from .utils import ('
55 63 stringutil,
56 64 )
57 65
58 if pycompat.TYPE_CHECKING:
59 from typing import (
60 Iterable,
61 Iterator,
62 List,
63 Optional,
64 Tuple,
65 )
66 # keeps pyflakes happy
67 assert [
68 Iterable,
69 Iterator,
70 List,
71 Optional,
72 Tuple,
73 ]
66 74
67 75
68 76 base85 = policy.importmod('base85')
@@ -10,6 +10,15 b' import calendar'
10 10 import datetime
11 11 import time
12 12
13 from typing import (
14 Callable,
15 Dict,
16 Iterable,
17 Optional,
18 Tuple,
19 Union,
20 )
21
13 22 from ..i18n import _
14 23 from .. import (
15 24 encoding,
@@ -17,17 +26,17 b' from .. import ('
17 26 pycompat,
18 27 )
19 28
20 if pycompat.TYPE_CHECKING:
21 from typing import (
22 Callable,
23 Dict,
24 Iterable,
25 Optional,
26 Tuple,
27 Union,
28 )
29 # keeps pyflakes happy
30 assert [
31 Callable,
32 Dict,
33 Iterable,
34 Optional,
35 Tuple,
36 Union,
37 ]
29 38
30 hgdate = Tuple[float, int] # (unixtime, offset)
39 hgdate = Tuple[float, int] # (unixtime, offset)
31 40
32 41 # used by parsedate
33 42 defaultdateformats = (
@@ -8,6 +8,10 b' import os'
8 8 import re as remod
9 9 import socket
10 10
11 from typing import (
12 Union,
13 )
14
11 15 from ..i18n import _
12 16 from .. import (
13 17 encoding,
@@ -24,11 +28,8 b' from ..revlogutils import ('
24 28 constants as revlog_constants,
25 29 )
26 30
27
28 if pycompat.TYPE_CHECKING:
29 from typing import (
30 Union,
31 )
31 # keeps pyflakes happy
32 assert [Union]
32 33
33 34 urlreq = urllibcompat.urlreq
34 35
@@ -61,13 +61,7 b' testpid = win32.testpid'
61 61 unlink = win32.unlink
62 62
63 63 if typing.TYPE_CHECKING:
64 # Replace the various overloads that come along with aliasing stdlib methods
65 # with the narrow definition that we care about in the type checking phase
66 # only. This ensures that both Windows and POSIX see only the definition
67 # that is actually available.
68 #
69 # Note that if we check pycompat.TYPE_CHECKING here, it is always False, and
70 # the methods aren't replaced.
64
71 65 def split(p: bytes) -> Tuple[bytes, bytes]:
72 66 raise NotImplementedError
73 67
General Comments 0
You need to be logged in to leave comments. Login now