Improve traceback (#465)

This commit is contained in:
Valérian Rousset
2016-08-10 20:18:35 +02:00
committed by Guido van Rossum
parent 231ebbefaa
commit 4e55f0561f
4 changed files with 102 additions and 41 deletions

View File

@@ -1,20 +0,0 @@
from typing import Any, IO, AnyStr, Callable, Tuple, List
from types import TracebackType, FrameType
ExtractTbResult = List[Tuple[str, int, str, str]]
def print_tb(traceback: TracebackType, limit: int = ..., file: IO[str] = ...) -> None: ...
def print_exception(type: type, value: Exception, limit: int = ..., file: IO[str] = ...) -> None: ...
def print_exc(limit: int = ..., file: IO[str] = ...) -> None: ...
def format_exc(limit: int = ...) -> str: ...
def print_last(limit: int = ..., file: IO[str] = ...) -> None: ...
def print_stack(f: FrameType = ..., limit: int = ..., file: IO[AnyStr] = ...) -> None: ...
def extract_tb(f: TracebackType, limit: int = ...) -> ExtractTbResult: ...
def extract_stack(f: FrameType = ..., limit: int = ...) -> ExtractTbResult: ...
def format_list(list: ExtractTbResult) -> List[str]: ...
def format_exception_only(type: type, value: List[str]) -> List[str]: ...
def format_exception(type: type, value: BaseException, tb: TracebackType, limit: int = ...) -> List[str]: ...
def format_tb(f: TracebackType, limit: int = ...) -> List[str]: ...
def format_stack(f: FrameType = ..., limit: int = ...) -> List[str]: ...
def tb_lineno(tb: TracebackType) -> AnyStr: ...
def _print(f: IO[str], str: str = ..., terminator: str = ...) -> None: ...

100
stdlib/2and3/traceback.pyi Normal file
View File

@@ -0,0 +1,100 @@
# Stubs for traceback
from typing import Generator, IO, Iterator, Mapping, Optional, Tuple, Type
from types import FrameType, TracebackType
import sys
_PT = Tuple[str, int, str, Optional[str]]
def print_tb(tb: TracebackType, limit: Optional[int] = ...,
file: Optional[IO[str]] = ...) -> None: ...
if sys.version_info >= (3,):
def print_exception(etype: Type[BaseException], value: BaseException,
tb: Optional[TracebackType], limit: Optional[int] = ...,
file: Optional[IO[str]] = ...,
chain: bool = ...) -> None: ...
def print_exc(limit: Optional[int] = ..., file: Optional[IO[str]] = ...,
chain: bool = ...) -> None: ...
def print_last(limit: Optional[int] = ..., file: Optional[IO[str]] = ...,
chain: bool = ...) -> None: ...
else:
def print_exception(etype: Type[BaseException], value: BaseException,
tb: Optional[TracebackType], limit: Optional[int] = ...,
file: Optional[IO[str]] = ...) -> None: ...
def print_exc(limit: Optional[int] = ...,
file: Optional[IO[str]] = ...) -> None: ...
def print_last(limit: Optional[int] = ...,
file: Optional[IO[str]] = ...) -> None: ...
def print_stack(f: Optional[FrameType] = ..., limit: Optional[int] = ...,
file: Optional[IO[str]] = ...) -> None: ...
def extract_tb(tb: TracebackType, limit: Optional[int] = ...) -> List[_PT]: ...
def extract_stack(f: Optional[FrameType] = ...,
limit: Optional[int] = ...) -> List[_PT]: ...
def format_list(extracted_list: List[_PT]) -> List[str]: ...
def format_exception_only(etype: Type[BaseException],
value: BaseException) -> List[str]: ...
if sys.version_info >= (3,):
def format_exception(etype: Type[BaseException], value: BaseException,
tb: TracebackType, limit: Optional[int] = ...,
chain: bool = ...) -> List[str]: ...
def format_exc(limit: Optional[int] = ..., chain: bool = ...) -> str: ...
else:
def format_exception(etype: Type[BaseException], value: BaseException,
tb: TracebackType,
limit: Optional[int] = ...) -> List[str]: ...
def format_exc(limit: Optional[int] = ...) -> str: ...
def format_tb(tb: TracebackType, limit: Optional[int] = ...) -> List[str]: ...
def format_stack(f: Optional[FrameType] = ...,
limit: Optional[int] = ...) -> List[str]: ...
if sys.version_info >= (3, 4):
def clear_frames(tb: TracebackType) -> None: ...
if sys.version_info >= (3, 5):
def walk_stack(f: Optional[FrameType]) -> Iterator[Tuple[FrameType, int]]: ...
def walk_tb(tb: TracebackType) -> Iterator[Tuple[FrameType, int]]: ...
if sys.version_info < (3,):
def tb_lineno(tb: TracebackType) -> int: ...
if sys.version_info >= (3, 5):
class TracebackException:
__cause__ = ... # type:TracebackException
__context__ = ... # type:TracebackException
__suppress_context__ = ... # type: bool
stack = ... # type: StackSummary
exc_type = ... # type: Type[BaseException]
filename = ... # type: str
lineno = ... # type: int
text = ... # type: str
offset = ... # type: int
msg = ... # type: str
def __init__(self, exc_type: Type[BaseException],
exc_value: BaseException, exc_traceback: TracebackType,
*, limit: Optional[int] = ..., lookup_lines: bool = ...,
capture_locals: bool = ...) -> None: ...
@classmethod
def from_exception(cls, exc: BaseException,
*, limit: Optional[int] = ...,
lookup_lines: bool = ...,
capture_locals: bool = ...) -> TracebackException: ...
def format(self, *, chain: bool = ...) -> Generator[str, None, None]: ...
def format_exception_only(self) -> Generator[str, None, None]: ...
if sys.version_info >= (3, 5):
class StackSummary:
@classmethod
def extract(cls,
frame_gen: Generator[Tuple[FrameType, int], None, None],
*, limit: Optional[int] = ..., lookup_lines: bool = ...,
capture_locals: bool = ...) -> StackSummary: ...
@classmethod
def from_list(cls, a_list: List[_PT]) -> StackSummary: ...
if sys.version_info >= (3, 5):
class FrameSummary:
def __init__(self, filename: str, lineno: int, name: str,
lookup_line: bool = ...,
locals: Optional[Mapping[str, str]] = ...,
line: Optional[int] = ...) -> None: ...

View File

@@ -5,7 +5,7 @@
from typing import (
List, Sequence, Any, Dict, Tuple, TextIO, overload, Optional, Union,
TypeVar, Callable
TypeVar, Callable, Type,
)
from types import TracebackType
@@ -118,7 +118,7 @@ def displayhook(value: Optional[int]) -> None: ...
def excepthook(type_: type, value: BaseException,
traceback: TracebackType) -> None: ...
# TODO should be a union of tuple, see mypy#1178
def exc_info() -> Tuple[Optional[type],
def exc_info() -> Tuple[Optional[Type[BaseException]],
Optional[BaseException],
Optional[TracebackType]]: ...
# sys.exit() accepts an optional argument of anything printable

View File

@@ -1,19 +0,0 @@
# Stubs for traceback
from typing import IO, List
from types import TracebackType, FrameType
import typing
# TODO signatures
def format_exception_only(etype, value) -> List[str]: ...
def format_exception(type: type, value: BaseException, tb: TracebackType, limit: int = ..., chain: bool = ...) -> List[str]: ...
def format_tb(traceback): ...
def print_exc(limit=..., file=..., chain=...): ...
def format_exc(limit: int = ..., chain: bool = ...) -> str: ...
def extract_stack(f=..., limit=...): ...
def extract_tb(traceback, limit=...): ...
def format_list(list): ...
def format_stack(f=..., limit=...) -> List[str]: ...
def print_stack(f: FrameType = ..., limit: int = ..., file: IO[str] = ...) -> None: ...
# TODO add more