From 0c9a8fbc79c2a0163b6cf146460132ff187c70f3 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Tue, 15 Oct 2019 15:31:25 -0400 Subject: [PATCH 1/6] Create cgitb stubs --- stdlib/2and3/cgitb.pyi | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 stdlib/2and3/cgitb.pyi diff --git a/stdlib/2and3/cgitb.pyi b/stdlib/2and3/cgitb.pyi new file mode 100644 index 000000000000..5b7ef3edf891 --- /dev/null +++ b/stdlib/2and3/cgitb.pyi @@ -0,0 +1,31 @@ + +from typing import Dict, Any, List, Tuple, Optional, Callable, Type, Union, IO, AnyStr +from types import FrameType, TracebackType +from os import PathLike +import sys + + +if sys.version_info >= (3, 6): + _Path = Union[AnyStr, PathLike[AnyStr]] +else: + _Path = AnyStr + + +def reset() -> str: ... +def small(text: str) -> str: ... +def strong(text: str) -> str: ... +def grey(text: str) -> str: ... +def lookup(name: str, frame: FrameType, locals: Dict[str, Any]) -> Tuple[Optional[str], Any]: ... +def scanvars(reader: Callable[[], bytes], frame: FrameType, locals: Dict[str, Any]) -> List[Tuple[str, Optional[str], Any]]: ... +def html(einfo: Tuple[Type[BaseException], BaseException, TracebackType], context: int = ...) -> str: ... +def text(einfo: Tuple[Type[BaseException], BaseException, TracebackType], context: int = ...) -> str: ... + +class Hook: + + def __init__(self, display: int = ..., logdir: Optional[_Path] = ..., context: int = ..., file: Optional[IO[str]] = ..., format: str = ...) -> None: ... + def __call__(self, etype: Optional[Type[BaseException]], evalue: Optional[BaseException], etb: Optional[TracebackType]) -> None: ... + def handle(self, info: Optional[Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]]] = ...) -> None: ... + +handler: Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], None] + +def enable(display: int = ..., logdir: Optional[_Path] = ..., context: int = ..., format: str = ...) -> None: ... From a959450ed81dbdef13cfda3566699399e17ed8c5 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Tue, 15 Oct 2019 15:33:22 -0400 Subject: [PATCH 2/6] Make _ExcInfo type binding, for ease of understanding --- stdlib/2and3/cgitb.pyi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stdlib/2and3/cgitb.pyi b/stdlib/2and3/cgitb.pyi index 5b7ef3edf891..a82efa352041 100644 --- a/stdlib/2and3/cgitb.pyi +++ b/stdlib/2and3/cgitb.pyi @@ -5,6 +5,7 @@ from os import PathLike import sys +_ExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] if sys.version_info >= (3, 6): _Path = Union[AnyStr, PathLike[AnyStr]] else: @@ -17,14 +18,14 @@ def strong(text: str) -> str: ... def grey(text: str) -> str: ... def lookup(name: str, frame: FrameType, locals: Dict[str, Any]) -> Tuple[Optional[str], Any]: ... def scanvars(reader: Callable[[], bytes], frame: FrameType, locals: Dict[str, Any]) -> List[Tuple[str, Optional[str], Any]]: ... -def html(einfo: Tuple[Type[BaseException], BaseException, TracebackType], context: int = ...) -> str: ... -def text(einfo: Tuple[Type[BaseException], BaseException, TracebackType], context: int = ...) -> str: ... +def html(einfo: _ExcInfo, context: int = ...) -> str: ... +def text(einfo: _ExcInfo, context: int = ...) -> str: ... class Hook: def __init__(self, display: int = ..., logdir: Optional[_Path] = ..., context: int = ..., file: Optional[IO[str]] = ..., format: str = ...) -> None: ... def __call__(self, etype: Optional[Type[BaseException]], evalue: Optional[BaseException], etb: Optional[TracebackType]) -> None: ... - def handle(self, info: Optional[Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]]] = ...) -> None: ... + def handle(self, info: Optional[_ExcInfo] = ...) -> None: ... handler: Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], None] From 2f5db4278f755a302babbd901565456a5090455f Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Tue, 15 Oct 2019 15:40:38 -0400 Subject: [PATCH 3/6] Fix _Path type use --- stdlib/2and3/cgitb.pyi | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/stdlib/2and3/cgitb.pyi b/stdlib/2and3/cgitb.pyi index a82efa352041..29e82c28958a 100644 --- a/stdlib/2and3/cgitb.pyi +++ b/stdlib/2and3/cgitb.pyi @@ -1,15 +1,16 @@ -from typing import Dict, Any, List, Tuple, Optional, Callable, Type, Union, IO, AnyStr +from typing import Dict, Any, List, Tuple, Optional, Callable, Type, Union, IO, AnyStr, TypeVar from types import FrameType, TracebackType -from os import PathLike import sys +_T = TypeVar("_T") _ExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] if sys.version_info >= (3, 6): - _Path = Union[AnyStr, PathLike[AnyStr]] + from os import PathLike + _Path = Union[_T, PathLike[_T]] else: - _Path = AnyStr + _Path = Union[_T] def reset() -> str: ... @@ -23,10 +24,10 @@ def text(einfo: _ExcInfo, context: int = ...) -> str: ... class Hook: - def __init__(self, display: int = ..., logdir: Optional[_Path] = ..., context: int = ..., file: Optional[IO[str]] = ..., format: str = ...) -> None: ... + def __init__(self, display: int = ..., logdir: Optional[_Path[AnyStr]] = ..., context: int = ..., file: Optional[IO[str]] = ..., format: str = ...) -> None: ... def __call__(self, etype: Optional[Type[BaseException]], evalue: Optional[BaseException], etb: Optional[TracebackType]) -> None: ... def handle(self, info: Optional[_ExcInfo] = ...) -> None: ... handler: Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], None] -def enable(display: int = ..., logdir: Optional[_Path] = ..., context: int = ..., format: str = ...) -> None: ... +def enable(display: int = ..., logdir: Optional[_Path[AnyStr]] = ..., context: int = ..., format: str = ...) -> None: ... From eef6a78880f523f053db92b107d6a0c0ab3e5b89 Mon Sep 17 00:00:00 2001 From: CraftSpider Date: Wed, 16 Oct 2019 08:00:11 -0400 Subject: [PATCH 4/6] Review changes, add undocumented and handler -> def --- stdlib/2and3/cgitb.pyi | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/stdlib/2and3/cgitb.pyi b/stdlib/2and3/cgitb.pyi index 29e82c28958a..d92f76a48700 100644 --- a/stdlib/2and3/cgitb.pyi +++ b/stdlib/2and3/cgitb.pyi @@ -13,21 +13,21 @@ else: _Path = Union[_T] -def reset() -> str: ... -def small(text: str) -> str: ... -def strong(text: str) -> str: ... -def grey(text: str) -> str: ... -def lookup(name: str, frame: FrameType, locals: Dict[str, Any]) -> Tuple[Optional[str], Any]: ... -def scanvars(reader: Callable[[], bytes], frame: FrameType, locals: Dict[str, Any]) -> List[Tuple[str, Optional[str], Any]]: ... +def reset() -> str: ... # undocumented +def small(text: str) -> str: ... # undocumented +def strong(text: str) -> str: ... # undocumented +def grey(text: str) -> str: ... # undocumented +def lookup(name: str, frame: FrameType, locals: Dict[str, Any]) -> Tuple[Optional[str], Any]: ... # undocumented +def scanvars(reader: Callable[[], bytes], frame: FrameType, locals: Dict[str, Any]) -> List[Tuple[str, Optional[str], Any]]: ... # undocumented def html(einfo: _ExcInfo, context: int = ...) -> str: ... def text(einfo: _ExcInfo, context: int = ...) -> str: ... -class Hook: +class Hook: # undocumented def __init__(self, display: int = ..., logdir: Optional[_Path[AnyStr]] = ..., context: int = ..., file: Optional[IO[str]] = ..., format: str = ...) -> None: ... def __call__(self, etype: Optional[Type[BaseException]], evalue: Optional[BaseException], etb: Optional[TracebackType]) -> None: ... def handle(self, info: Optional[_ExcInfo] = ...) -> None: ... -handler: Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], None] +def handler(etype: Optional[Type[BaseException]], evalue: Optional[BaseException], etb: Optional[TracebackType]) -> None: ... def enable(display: int = ..., logdir: Optional[_Path[AnyStr]] = ..., context: int = ..., format: str = ...) -> None: ... From 992a9b2ed4a4c71ceecbb682e502ad5b1c9fc000 Mon Sep 17 00:00:00 2001 From: CraftSpider Date: Wed, 16 Oct 2019 08:05:43 -0400 Subject: [PATCH 5/6] Fix type of `handler` --- stdlib/2and3/cgitb.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2and3/cgitb.pyi b/stdlib/2and3/cgitb.pyi index d92f76a48700..96cd891846b9 100644 --- a/stdlib/2and3/cgitb.pyi +++ b/stdlib/2and3/cgitb.pyi @@ -28,6 +28,6 @@ class Hook: # undocumented def __call__(self, etype: Optional[Type[BaseException]], evalue: Optional[BaseException], etb: Optional[TracebackType]) -> None: ... def handle(self, info: Optional[_ExcInfo] = ...) -> None: ... -def handler(etype: Optional[Type[BaseException]], evalue: Optional[BaseException], etb: Optional[TracebackType]) -> None: ... +def handler(info: Optional[_ExcInfo]) -> None: ... def enable(display: int = ..., logdir: Optional[_Path[AnyStr]] = ..., context: int = ..., format: str = ...) -> None: ... From 7c2a0485387192b5b12339e811fd8b7a756eb7ff Mon Sep 17 00:00:00 2001 From: CraftSpider Date: Wed, 16 Oct 2019 08:11:28 -0400 Subject: [PATCH 6/6] Add that the handler argument is unecessary --- stdlib/2and3/cgitb.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2and3/cgitb.pyi b/stdlib/2and3/cgitb.pyi index 96cd891846b9..ded055cb485c 100644 --- a/stdlib/2and3/cgitb.pyi +++ b/stdlib/2and3/cgitb.pyi @@ -28,6 +28,6 @@ class Hook: # undocumented def __call__(self, etype: Optional[Type[BaseException]], evalue: Optional[BaseException], etb: Optional[TracebackType]) -> None: ... def handle(self, info: Optional[_ExcInfo] = ...) -> None: ... -def handler(info: Optional[_ExcInfo]) -> None: ... +def handler(info: Optional[_ExcInfo] = ...) -> None: ... def enable(display: int = ..., logdir: Optional[_Path[AnyStr]] = ..., context: int = ..., format: str = ...) -> None: ...