Fix Python 2's traceback.format_exception, traceback.print_exception (#1512)

E.g. it's legal to call traceback.format_exception(None, None, None). In
particular, this change makes the following idiom type-check:
  import traceback
  import sys
  exc_type, exc_value, exc_traceback = sys.exc_info()
  traceback.format_exception(exc_type, exc_value, exc_traceback)
This commit is contained in:
Matthias Kramm
2017-08-03 15:58:34 -07:00
committed by Guido van Rossum
parent 7a580ed0a9
commit 3638bc1f52

View File

@@ -19,7 +19,8 @@ if sys.version_info >= (3,):
def print_last(limit: Optional[int] = ..., file: Optional[IO[str]] = ...,
chain: bool = ...) -> None: ...
else:
def print_exception(etype: Type[BaseException], value: BaseException,
def print_exception(etype: Optional[Type[BaseException]],
value: Optional[BaseException],
tb: Optional[TracebackType], limit: Optional[int] = ...,
file: Optional[IO[str]] = ...) -> None: ...
def print_exc(limit: Optional[int] = ...,
@@ -47,8 +48,9 @@ if sys.version_info >= (3,):
chain: bool = ...) -> List[str]: ...
def format_exc(limit: Optional[int] = ..., chain: bool = ...) -> str: ...
else:
def format_exception(etype: Type[BaseException], value: BaseException,
tb: TracebackType,
def format_exception(etype: Optional[Type[BaseException]],
value: Optional[BaseException],
tb: Optional[TracebackType],
limit: Optional[int] = ...) -> List[str]: ...
def format_exc(limit: Optional[int] = ...) -> str: ...
def format_tb(tb: Optional[TracebackType], limit: Optional[int] = ...) -> List[str]: ...