##// END OF EJS Templates
pytype: stop excluding mercurial/ui.py...
Matt Harbison -
r50688:8147abc0 default
parent child Browse files
Show More
@@ -0,0 +1,28 b''
1 # typelib.py - type hint aliases and support
2 #
3 # Copyright 2022 Matt Harbison <matt_harbison@yahoo.com>
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
7
8 import typing
9
10 # Note: this is slightly different from pycompat.TYPE_CHECKING, as using
11 # pycompat causes the BinaryIO_Proxy type to be resolved to ``object`` when
12 # used as the base class during a pytype run.
13 TYPE_CHECKING = typing.TYPE_CHECKING
14
15
16 # The BinaryIO class provides empty methods, which at runtime means that
17 # ``__getattr__`` on the proxy classes won't get called for the methods that
18 # should delegate to the internal object. So to avoid runtime changes because
19 # of the required typing inheritance, just use BinaryIO when typechecking, and
20 # ``object`` otherwise.
21 if TYPE_CHECKING:
22 from typing import (
23 BinaryIO,
24 )
25
26 BinaryIO_Proxy = BinaryIO
27 else:
28 BinaryIO_Proxy = object
@@ -31,7 +31,6 b' cd `hg root`'
31 31 # mercurial/pure/parsers.py # [attribute-error]
32 32 # mercurial/repoview.py # [attribute-error]
33 33 # mercurial/testing/storage.py # tons of [attribute-error]
34 # mercurial/ui.py # [attribute-error], [wrong-arg-types]
35 34 # mercurial/unionrepo.py # ui, svfs, unfiltered [attribute-error]
36 35 # mercurial/win32.py # [not-callable]
37 36 # mercurial/wireprotoframing.py # [unsupported-operands], [attribute-error], [import-error]
@@ -64,7 +63,6 b' pytype -V 3.7 --keep-going --jobs auto m'
64 63 -x mercurial/repoview.py \
65 64 -x mercurial/testing/storage.py \
66 65 -x mercurial/thirdparty \
67 -x mercurial/ui.py \
68 66 -x mercurial/unionrepo.py \
69 67 -x mercurial/win32.py \
70 68 -x mercurial/wireprotoframing.py \
@@ -1795,6 +1795,9 b' class ui:'
1795 1795 # choices containing spaces, ASCII, or basically anything
1796 1796 # except an ampersand followed by a character.
1797 1797 m = re.match(br'(?s)(.+?)\$\$([^$]*&[^ $].*)', prompt)
1798
1799 assert m is not None # help pytype
1800
1798 1801 msg = m.group(1)
1799 1802 choices = [p.strip(b' ') for p in m.group(2).split(b'$$')]
1800 1803
@@ -18,6 +18,10 b' import sys'
18 18 import threading
19 19 import time
20 20
21 from typing import (
22 BinaryIO,
23 )
24
21 25 from ..i18n import _
22 26 from ..pycompat import (
23 27 getattr,
@@ -29,6 +33,7 b' from .. import ('
29 33 error,
30 34 policy,
31 35 pycompat,
36 typelib,
32 37 )
33 38
34 39 # Import like this to keep import-checker happy
@@ -118,8 +123,8 b' def unwrap_line_buffered(stream):'
118 123 return stream
119 124
120 125
121 class WriteAllWrapper:
122 def __init__(self, orig):
126 class WriteAllWrapper(typelib.BinaryIO_Proxy):
127 def __init__(self, orig: BinaryIO):
123 128 self.orig = orig
124 129
125 130 def __getattr__(self, attr):
@@ -16,6 +16,10 b' import string'
16 16 import sys
17 17 import winreg # pytype: disable=import-error
18 18
19 from typing import (
20 BinaryIO,
21 )
22
19 23 from .i18n import _
20 24 from .pycompat import getattr
21 25 from . import (
@@ -23,6 +27,7 b' from . import ('
23 27 error,
24 28 policy,
25 29 pycompat,
30 typelib,
26 31 win32,
27 32 )
28 33
@@ -208,7 +213,7 b' def get_password():'
208 213 return encoding.unitolocal(pw)
209 214
210 215
211 class winstdout:
216 class winstdout(typelib.BinaryIO_Proxy):
212 217 """Some files on Windows misbehave.
213 218
214 219 When writing to a broken pipe, EINVAL instead of EPIPE may be raised.
@@ -217,7 +222,7 b' class winstdout:'
217 222 error may happen. Python 3 already works around that.
218 223 """
219 224
220 def __init__(self, fp):
225 def __init__(self, fp: BinaryIO):
221 226 self.fp = fp
222 227
223 228 def __getattr__(self, key):
General Comments 0
You need to be logged in to leave comments. Login now