Skip to content

Commit 3638bc1

Browse files
matthiaskrammgvanrossum
authored andcommitted
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)
1 parent 7a580ed commit 3638bc1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

stdlib/2and3/traceback.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ if sys.version_info >= (3,):
1919
def print_last(limit: Optional[int] = ..., file: Optional[IO[str]] = ...,
2020
chain: bool = ...) -> None: ...
2121
else:
22-
def print_exception(etype: Type[BaseException], value: BaseException,
22+
def print_exception(etype: Optional[Type[BaseException]],
23+
value: Optional[BaseException],
2324
tb: Optional[TracebackType], limit: Optional[int] = ...,
2425
file: Optional[IO[str]] = ...) -> None: ...
2526
def print_exc(limit: Optional[int] = ...,
@@ -47,8 +48,9 @@ if sys.version_info >= (3,):
4748
chain: bool = ...) -> List[str]: ...
4849
def format_exc(limit: Optional[int] = ..., chain: bool = ...) -> str: ...
4950
else:
50-
def format_exception(etype: Type[BaseException], value: BaseException,
51-
tb: TracebackType,
51+
def format_exception(etype: Optional[Type[BaseException]],
52+
value: Optional[BaseException],
53+
tb: Optional[TracebackType],
5254
limit: Optional[int] = ...) -> List[str]: ...
5355
def format_exc(limit: Optional[int] = ...) -> str: ...
5456
def format_tb(tb: Optional[TracebackType], limit: Optional[int] = ...) -> List[str]: ...

0 commit comments

Comments
 (0)