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 | # mercurial/pure/parsers.py # [attribute-error] |
|
31 | # mercurial/pure/parsers.py # [attribute-error] | |
32 | # mercurial/repoview.py # [attribute-error] |
|
32 | # mercurial/repoview.py # [attribute-error] | |
33 | # mercurial/testing/storage.py # tons of [attribute-error] |
|
33 | # mercurial/testing/storage.py # tons of [attribute-error] | |
34 | # mercurial/ui.py # [attribute-error], [wrong-arg-types] |
|
|||
35 | # mercurial/unionrepo.py # ui, svfs, unfiltered [attribute-error] |
|
34 | # mercurial/unionrepo.py # ui, svfs, unfiltered [attribute-error] | |
36 | # mercurial/win32.py # [not-callable] |
|
35 | # mercurial/win32.py # [not-callable] | |
37 | # mercurial/wireprotoframing.py # [unsupported-operands], [attribute-error], [import-error] |
|
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 | -x mercurial/repoview.py \ |
|
63 | -x mercurial/repoview.py \ | |
65 | -x mercurial/testing/storage.py \ |
|
64 | -x mercurial/testing/storage.py \ | |
66 | -x mercurial/thirdparty \ |
|
65 | -x mercurial/thirdparty \ | |
67 | -x mercurial/ui.py \ |
|
|||
68 | -x mercurial/unionrepo.py \ |
|
66 | -x mercurial/unionrepo.py \ | |
69 | -x mercurial/win32.py \ |
|
67 | -x mercurial/win32.py \ | |
70 | -x mercurial/wireprotoframing.py \ |
|
68 | -x mercurial/wireprotoframing.py \ |
@@ -1795,6 +1795,9 b' class ui:' | |||||
1795 | # choices containing spaces, ASCII, or basically anything |
|
1795 | # choices containing spaces, ASCII, or basically anything | |
1796 | # except an ampersand followed by a character. |
|
1796 | # except an ampersand followed by a character. | |
1797 | m = re.match(br'(?s)(.+?)\$\$([^$]*&[^ $].*)', prompt) |
|
1797 | m = re.match(br'(?s)(.+?)\$\$([^$]*&[^ $].*)', prompt) | |
|
1798 | ||||
|
1799 | assert m is not None # help pytype | |||
|
1800 | ||||
1798 | msg = m.group(1) |
|
1801 | msg = m.group(1) | |
1799 | choices = [p.strip(b' ') for p in m.group(2).split(b'$$')] |
|
1802 | choices = [p.strip(b' ') for p in m.group(2).split(b'$$')] | |
1800 |
|
1803 |
@@ -18,6 +18,10 b' import sys' | |||||
18 | import threading |
|
18 | import threading | |
19 | import time |
|
19 | import time | |
20 |
|
20 | |||
|
21 | from typing import ( | |||
|
22 | BinaryIO, | |||
|
23 | ) | |||
|
24 | ||||
21 | from ..i18n import _ |
|
25 | from ..i18n import _ | |
22 | from ..pycompat import ( |
|
26 | from ..pycompat import ( | |
23 | getattr, |
|
27 | getattr, | |
@@ -29,6 +33,7 b' from .. import (' | |||||
29 | error, |
|
33 | error, | |
30 | policy, |
|
34 | policy, | |
31 | pycompat, |
|
35 | pycompat, | |
|
36 | typelib, | |||
32 | ) |
|
37 | ) | |
33 |
|
38 | |||
34 | # Import like this to keep import-checker happy |
|
39 | # Import like this to keep import-checker happy | |
@@ -118,8 +123,8 b' def unwrap_line_buffered(stream):' | |||||
118 | return stream |
|
123 | return stream | |
119 |
|
124 | |||
120 |
|
125 | |||
121 | class WriteAllWrapper: |
|
126 | class WriteAllWrapper(typelib.BinaryIO_Proxy): | |
122 | def __init__(self, orig): |
|
127 | def __init__(self, orig: BinaryIO): | |
123 | self.orig = orig |
|
128 | self.orig = orig | |
124 |
|
129 | |||
125 | def __getattr__(self, attr): |
|
130 | def __getattr__(self, attr): |
@@ -16,6 +16,10 b' import string' | |||||
16 | import sys |
|
16 | import sys | |
17 | import winreg # pytype: disable=import-error |
|
17 | import winreg # pytype: disable=import-error | |
18 |
|
18 | |||
|
19 | from typing import ( | |||
|
20 | BinaryIO, | |||
|
21 | ) | |||
|
22 | ||||
19 | from .i18n import _ |
|
23 | from .i18n import _ | |
20 | from .pycompat import getattr |
|
24 | from .pycompat import getattr | |
21 | from . import ( |
|
25 | from . import ( | |
@@ -23,6 +27,7 b' from . import (' | |||||
23 | error, |
|
27 | error, | |
24 | policy, |
|
28 | policy, | |
25 | pycompat, |
|
29 | pycompat, | |
|
30 | typelib, | |||
26 | win32, |
|
31 | win32, | |
27 | ) |
|
32 | ) | |
28 |
|
33 | |||
@@ -208,7 +213,7 b' def get_password():' | |||||
208 | return encoding.unitolocal(pw) |
|
213 | return encoding.unitolocal(pw) | |
209 |
|
214 | |||
210 |
|
215 | |||
211 | class winstdout: |
|
216 | class winstdout(typelib.BinaryIO_Proxy): | |
212 | """Some files on Windows misbehave. |
|
217 | """Some files on Windows misbehave. | |
213 |
|
218 | |||
214 | When writing to a broken pipe, EINVAL instead of EPIPE may be raised. |
|
219 | When writing to a broken pipe, EINVAL instead of EPIPE may be raised. | |
@@ -217,7 +222,7 b' class winstdout:' | |||||
217 | error may happen. Python 3 already works around that. |
|
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 | self.fp = fp |
|
226 | self.fp = fp | |
222 |
|
227 | |||
223 | def __getattr__(self, key): |
|
228 | def __getattr__(self, key): |
General Comments 0
You need to be logged in to leave comments.
Login now