##// END OF EJS Templates
typing: explicitly type some `mercurial.util` eol code to avoid @overload...
Matt Harbison -
r52614:ed280858 default
parent child Browse files
Show More
@@ -32,10 +32,13 b' import stat'
32 32 import sys
33 33 import time
34 34 import traceback
35 import typing
35 36 import warnings
36 37
37 38 from typing import (
38 39 Any,
40 BinaryIO,
41 Callable,
39 42 Iterable,
40 43 Iterator,
41 44 List,
@@ -55,6 +58,7 b' from . import ('
55 58 i18n,
56 59 policy,
57 60 pycompat,
61 typelib,
58 62 urllibcompat,
59 63 )
60 64 from .utils import (
@@ -2907,20 +2911,20 b' bytecount = unitcountfn('
2907 2911 )
2908 2912
2909 2913
2910 class transformingwriter:
2914 class transformingwriter(typelib.BinaryIO_Proxy):
2911 2915 """Writable file wrapper to transform data by function"""
2912 2916
2913 def __init__(self, fp, encode):
2917 def __init__(self, fp: BinaryIO, encode: Callable[[bytes], bytes]) -> None:
2914 2918 self._fp = fp
2915 2919 self._encode = encode
2916 2920
2917 def close(self):
2921 def close(self) -> None:
2918 2922 self._fp.close()
2919 2923
2920 def flush(self):
2924 def flush(self) -> None:
2921 2925 self._fp.flush()
2922 2926
2923 def write(self, data):
2927 def write(self, data: bytes) -> int:
2924 2928 return self._fp.write(self._encode(data))
2925 2929
2926 2930
@@ -2938,7 +2942,7 b' def tocrlf(s: bytes) -> bytes:'
2938 2942 return _eolre.sub(b'\r\n', s)
2939 2943
2940 2944
2941 def _crlfwriter(fp):
2945 def _crlfwriter(fp: typelib.BinaryIO_Proxy) -> typelib.BinaryIO_Proxy:
2942 2946 return transformingwriter(fp, tocrlf)
2943 2947
2944 2948
@@ -2951,6 +2955,21 b' else:'
2951 2955 fromnativeeol = pycompat.identity
2952 2956 nativeeolwriter = pycompat.identity
2953 2957
2958 if typing.TYPE_CHECKING:
2959 # Replace the various overloads that come along with aliasing other methods
2960 # with the narrow definition that we care about in the type checking phase
2961 # only. This ensures that both Windows and POSIX see only the definition
2962 # that is actually available.
2963
2964 def tonativeeol(s: bytes) -> bytes:
2965 raise NotImplementedError
2966
2967 def fromnativeeol(s: bytes) -> bytes:
2968 raise NotImplementedError
2969
2970 def nativeeolwriter(fp: typelib.BinaryIO_Proxy) -> typelib.BinaryIO_Proxy:
2971 raise NotImplementedError
2972
2954 2973
2955 2974 # TODO delete since workaround variant for Python 2 no longer needed.
2956 2975 def iterfile(fp):
General Comments 0
You need to be logged in to leave comments. Login now