From ba026fc120f3d62849dd2d9d41efe45a0996f2d1 Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Wed, 16 Mar 2016 18:30:37 +0100 Subject: [PATCH 01/14] fileinput first version --- stdlib/3/fileinput.pyi | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 stdlib/3/fileinput.pyi diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi new file mode 100644 index 000000000..9be8d7133 --- /dev/null +++ b/stdlib/3/fileinput.pyi @@ -0,0 +1,49 @@ +from typing import Iterable, BinaryIO + +__all__ = ... # type: List[str] +_state = ... # type: None + +def input( + files = None, + inplace: bool = ..., + backup: str = ..., + bufsize: int = ..., + mode: str = ..., + openhook = None): ... + +def close() -> None : ... +def nextfile() -> None : ... +def filename() -> str : ... +def lineno() -> int : ... +def isfirstline() -> bool : ... +def isstdin() -> bool : ... + +class FileInput(Iterable): + def __init__( + self, + files = None, + inplace: bool = ..., + backup: str = ..., + bufsize: int = ..., + mode: str = ..., + openhook = None) -> None : ... + + + def __del__(self) -> None : ... + def close(self) -> None : ... + def __enter__(self) : ... #return self + def __exit__(self, type, value, traceback) -> None : ... + def __iter__(self) : ... #return self + def __next__(self) -> str : ... #return readline() + def __getitem__(self, i) -> str : ... #return next() + def nextfile(self) -> None : ... + def readline(self) -> str : ... + def filename(self) -> str : ... + def lineno(self) -> int : ... + def filelineno(self) -> int : ... + def fileno(self) -> int : ... + def isfirstline(self) -> bool : ... + def isstdin(self) -> bool : ... + +def hook_compressed(filename: str, mode: str) -> BinaryIO : ... +def hook_encoded(encoding: str) -> BinaryIO : ... From ac8ed664a98e9b7120d1d08097fc187ce3cfb4a5 Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Fri, 18 Mar 2016 19:40:49 +0100 Subject: [PATCH 02/14] without comments 2 --- stdlib/3/fileinput.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index 9be8d7133..aff9b2c9a 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -31,11 +31,11 @@ class FileInput(Iterable): def __del__(self) -> None : ... def close(self) -> None : ... - def __enter__(self) : ... #return self + def __enter__(self) : ... def __exit__(self, type, value, traceback) -> None : ... - def __iter__(self) : ... #return self - def __next__(self) -> str : ... #return readline() - def __getitem__(self, i) -> str : ... #return next() + def __iter__(self) : ... + def __next__(self) -> str : ... + def __getitem__(self, i) -> str : ... def nextfile(self) -> None : ... def readline(self) -> str : ... def filename(self) -> str : ... From 4fdf23d5bdbc51456cdc29e5ad93edbbc248e378 Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Sun, 20 Mar 2016 13:25:17 +0100 Subject: [PATCH 03/14] no unexported --- stdlib/3/fileinput.pyi | 3 --- 1 file changed, 3 deletions(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index aff9b2c9a..8e799c29e 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -1,8 +1,5 @@ from typing import Iterable, BinaryIO -__all__ = ... # type: List[str] -_state = ... # type: None - def input( files = None, inplace: bool = ..., From 78fa0cd5eb0ce810f1e02bcde9b5c1cc12cd176e Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Sun, 20 Mar 2016 13:49:37 +0100 Subject: [PATCH 04/14] pep8 --- stdlib/3/fileinput.pyi | 77 ++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index 8e799c29e..2d2cdd569 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -1,46 +1,49 @@ from typing import Iterable, BinaryIO -def input( - files = None, - inplace: bool = ..., - backup: str = ..., - bufsize: int = ..., - mode: str = ..., - openhook = None): ... -def close() -> None : ... -def nextfile() -> None : ... -def filename() -> str : ... -def lineno() -> int : ... -def isfirstline() -> bool : ... -def isstdin() -> bool : ... +def input( + files=None, + inplace: bool=..., + backup: str=..., + bufsize: int=..., + mode: str=..., + openhook=None + ): ... + + +def close() -> None: ... +def nextfile() -> None: ... +def filename() -> str: ... +def lineno() -> int: ... +def isfirstline() -> bool: ... +def isstdin() -> bool: ... class FileInput(Iterable): def __init__( self, - files = None, - inplace: bool = ..., - backup: str = ..., - bufsize: int = ..., - mode: str = ..., - openhook = None) -> None : ... + files=None, + inplace: bool=..., + backup: str=..., + bufsize: int=..., + mode: str=..., + openhook=None + ) -> None: ... + def __del__(self) -> None: ... + def close(self) -> None: ... + def __enter__(self): ... + def __exit__(self, type, value, traceback) -> None: ... + def __iter__(self): ... + def __next__(self) -> str: ... + def __getitem__(self, i) -> str: ... + def nextfile(self) -> None: ... + def readline(self) -> str: ... + def filename(self) -> str: ... + def lineno(self) -> int: ... + def filelineno(self) -> int: ... + def fileno(self) -> int: ... + def isfirstline(self) -> bool: ... + def isstdin(self) -> bool: ... - def __del__(self) -> None : ... - def close(self) -> None : ... - def __enter__(self) : ... - def __exit__(self, type, value, traceback) -> None : ... - def __iter__(self) : ... - def __next__(self) -> str : ... - def __getitem__(self, i) -> str : ... - def nextfile(self) -> None : ... - def readline(self) -> str : ... - def filename(self) -> str : ... - def lineno(self) -> int : ... - def filelineno(self) -> int : ... - def fileno(self) -> int : ... - def isfirstline(self) -> bool : ... - def isstdin(self) -> bool : ... - -def hook_compressed(filename: str, mode: str) -> BinaryIO : ... -def hook_encoded(encoding: str) -> BinaryIO : ... +def hook_compressed(filename: str, mode: str) -> BinaryIO: ... +def hook_encoded(encoding: str) -> BinaryIO: ... From 941f86a16361a45da92761f564e399006a629223 Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Sun, 20 Mar 2016 13:55:19 +0100 Subject: [PATCH 05/14] files type --- stdlib/3/fileinput.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index 2d2cdd569..7b2c21b1b 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -1,8 +1,8 @@ -from typing import Iterable, BinaryIO +from typing import Iterable, BinaryIO, List def input( - files=None, + files=List[str], inplace: bool=..., backup: str=..., bufsize: int=..., From d1baa1deaa1f2341d4c15b0c004a7e763f8834e3 Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Sun, 20 Mar 2016 14:03:47 +0100 Subject: [PATCH 06/14] missing one --- stdlib/3/fileinput.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index 7b2c21b1b..cf26b8234 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -21,7 +21,7 @@ def isstdin() -> bool: ... class FileInput(Iterable): def __init__( self, - files=None, + files=List[str], inplace: bool=..., backup: str=..., bufsize: int=..., From 703b88b0c0d36900ef40e8d12110b73770dfb308 Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Sun, 20 Mar 2016 14:10:33 +0100 Subject: [PATCH 07/14] openhook is callable --- stdlib/3/fileinput.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index cf26b8234..d39fe5826 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -7,7 +7,7 @@ def input( backup: str=..., bufsize: int=..., mode: str=..., - openhook=None + openhook: Callable[[str, str], BinaryIO]=... ): ... @@ -26,7 +26,7 @@ class FileInput(Iterable): backup: str=..., bufsize: int=..., mode: str=..., - openhook=None + openhook: Callable[[str, str], BinaryIO]=... ) -> None: ... def __del__(self) -> None: ... From 5ae1c1beb7cb3ac9063af6525683e5a9d8ae9244 Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Sun, 20 Mar 2016 14:20:24 +0100 Subject: [PATCH 08/14] wrong syntax --- stdlib/3/fileinput.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index d39fe5826..1d8ee2baa 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -2,7 +2,7 @@ from typing import Iterable, BinaryIO, List def input( - files=List[str], + files: List[str]=..., inplace: bool=..., backup: str=..., bufsize: int=..., @@ -21,7 +21,7 @@ def isstdin() -> bool: ... class FileInput(Iterable): def __init__( self, - files=List[str], + files: List[str]=..., inplace: bool=..., backup: str=..., bufsize: int=..., From 6df6bc8f8640ec65faced04c585a7fcd8ef2f94a Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Sun, 20 Mar 2016 21:54:24 +0100 Subject: [PATCH 09/14] missing callable --- stdlib/3/fileinput.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index 1d8ee2baa..04d8da79b 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -1,4 +1,4 @@ -from typing import Iterable, BinaryIO, List +from typing import Iterable, BinaryIO, List, Callable def input( From 871ebbf566d6ffe22446437501bc75a6860ea9d6 Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Mon, 21 Mar 2016 10:58:00 +0100 Subject: [PATCH 10/14] io anystr --- stdlib/3/fileinput.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index 04d8da79b..68ec815b7 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -1,4 +1,4 @@ -from typing import Iterable, BinaryIO, List, Callable +from typing import Iterable, BinaryIO, List, Callable, IO def input( @@ -7,7 +7,7 @@ def input( backup: str=..., bufsize: int=..., mode: str=..., - openhook: Callable[[str, str], BinaryIO]=... + openhook: Callable[[str, str], IO[AnyStr]]=... ): ... @@ -26,7 +26,7 @@ class FileInput(Iterable): backup: str=..., bufsize: int=..., mode: str=..., - openhook: Callable[[str, str], BinaryIO]=... + openhook: Callable[[str, str], IO[AnyStr]]=... ) -> None: ... def __del__(self) -> None: ... @@ -45,5 +45,5 @@ class FileInput(Iterable): def isfirstline(self) -> bool: ... def isstdin(self) -> bool: ... -def hook_compressed(filename: str, mode: str) -> BinaryIO: ... -def hook_encoded(encoding: str) -> BinaryIO: ... +def hook_compressed(filename: str, mode: str) -> IO[AnyStr]: ... +def hook_encoded(encoding: str) -> IO[AnyStr]: ... From a8d2158aaf33c167e24b2c2d19541fd94985bce5 Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Mon, 21 Mar 2016 11:00:55 +0100 Subject: [PATCH 11/14] missing import --- stdlib/3/fileinput.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index 68ec815b7..5fafaddeb 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -1,4 +1,4 @@ -from typing import Iterable, BinaryIO, List, Callable, IO +from typing import Iterable, BinaryIO, List, Callable, IO, AnyStr def input( From 83e51ac3cbd889915a3e84d6136b09a0f1ec6c59 Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Tue, 22 Mar 2016 06:33:31 +0100 Subject: [PATCH 12/14] inherit --- stdlib/3/fileinput.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index 5fafaddeb..ff64c40e0 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -1,4 +1,4 @@ -from typing import Iterable, BinaryIO, List, Callable, IO, AnyStr +from typing import Iterable, BinaryIO, List, Callable, IO, AnyStr, Generic def input( @@ -18,7 +18,7 @@ def lineno() -> int: ... def isfirstline() -> bool: ... def isstdin() -> bool: ... -class FileInput(Iterable): +class FileInput(Iterable[AnyStr], Generic[AnyStr]): def __init__( self, files: List[str]=..., From 2eaf1933b850039760af5e0cc4df01d23281508c Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Tue, 22 Mar 2016 08:38:08 +0100 Subject: [PATCH 13/14] files is optional --- stdlib/3/fileinput.pyi | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index ff64c40e0..3f0179216 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -1,8 +1,10 @@ -from typing import Iterable, BinaryIO, List, Callable, IO, AnyStr, Generic +from typing import Iterable, Callable, IO, AnyStr, Generic, Any, TypeVar + +StrOrIterableStr = TypeVar('StrOrIterableStr', str, Iterable[str]) def input( - files: List[str]=..., + files: StrOrIterableStr=None, inplace: bool=..., backup: str=..., bufsize: int=..., @@ -21,7 +23,7 @@ def isstdin() -> bool: ... class FileInput(Iterable[AnyStr], Generic[AnyStr]): def __init__( self, - files: List[str]=..., + files: StrOrIterableStr=None, inplace: bool=..., backup: str=..., bufsize: int=..., @@ -32,7 +34,7 @@ class FileInput(Iterable[AnyStr], Generic[AnyStr]): def __del__(self) -> None: ... def close(self) -> None: ... def __enter__(self): ... - def __exit__(self, type, value, traceback) -> None: ... + def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ... def __iter__(self): ... def __next__(self) -> str: ... def __getitem__(self, i) -> str: ... From 6d68962ed7766b5e4c217ca0e8be31e1f53c2f1e Mon Sep 17 00:00:00 2001 From: Julien Hebert Date: Wed, 23 Mar 2016 08:30:39 +0100 Subject: [PATCH 14/14] with Guido fixes --- stdlib/3/fileinput.pyi | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/stdlib/3/fileinput.pyi b/stdlib/3/fileinput.pyi index 3f0179216..7d68c2797 100644 --- a/stdlib/3/fileinput.pyi +++ b/stdlib/3/fileinput.pyi @@ -1,16 +1,13 @@ -from typing import Iterable, Callable, IO, AnyStr, Generic, Any, TypeVar - -StrOrIterableStr = TypeVar('StrOrIterableStr', str, Iterable[str]) +from typing import Iterable, Callable, IO, AnyStr, Generic, Any, Union, Iterator def input( - files: StrOrIterableStr=None, + files: Union[str, Iterable[str]]=None, inplace: bool=..., backup: str=..., bufsize: int=..., mode: str=..., - openhook: Callable[[str, str], IO[AnyStr]]=... - ): ... + openhook: Callable[[str, str], IO[AnyStr]]=...) -> Iterable[AnyStr]: ... def close() -> None: ... @@ -23,7 +20,7 @@ def isstdin() -> bool: ... class FileInput(Iterable[AnyStr], Generic[AnyStr]): def __init__( self, - files: StrOrIterableStr=None, + files: Union[str, Iterable[str]]=None, inplace: bool=..., backup: str=..., bufsize: int=..., @@ -33,13 +30,13 @@ class FileInput(Iterable[AnyStr], Generic[AnyStr]): def __del__(self) -> None: ... def close(self) -> None: ... - def __enter__(self): ... + def __enter__(self) -> 'FileInput[AnyStr]': ... def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ... - def __iter__(self): ... - def __next__(self) -> str: ... - def __getitem__(self, i) -> str: ... + def __iter__(self) -> Iterator[AnyStr]: ... + def __next__(self) -> AnyStr: ... + def __getitem__(self, i) -> AnyStr: ... def nextfile(self) -> None: ... - def readline(self) -> str: ... + def readline(self) -> AnyStr: ... def filename(self) -> str: ... def lineno(self) -> int: ... def filelineno(self) -> int: ...