Skip to content

Commit a5bbe2f

Browse files
Loosen parameters of format_list and from_list
Never ask for a List when asking for a MutableSequence will do. Never ask for a MutableSequence when asking for a Sequence will do. Never ask for a Sequence when asking for a Collection will do. Never ask for a Collection when asking for an Iterable will do. Also drop support for Tuple[str, int, str, Optional[str]] elements in the iterables passed to traceback.format_list and traceback.StackSummary.from_list - if authors are diligent enough to be type-checking their code, they are diligent enough to be making use of their dependencies according to their preferred semantics rather than their backwards-compatibility carve-outs.
1 parent cca6ee4 commit a5bbe2f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

stdlib/2and3/traceback.pyi

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Stubs for traceback
22

3-
from typing import Any, Dict, Generator, IO, Iterator, List, Mapping, Optional, Tuple, Type, Iterable
3+
from typing import Any, Dict, Generator, IO, Iterable, Iterator, List, Mapping, Optional, Tuple, Type
44
from types import FrameType, TracebackType
55
import sys
66

@@ -35,7 +35,10 @@ if sys.version_info >= (3, 5):
3535
def extract_tb(tb: Optional[TracebackType], limit: Optional[int] = ...) -> StackSummary: ...
3636
def extract_stack(f: Optional[FrameType] = ...,
3737
limit: Optional[int] = ...) -> StackSummary: ...
38-
def format_list(extracted_list: List[FrameSummary]) -> List[str]: ...
38+
# NOTE(https://bugs.python.org/issue34648): Authors who are diligent
39+
# enough to type-check their code are authors who are diligent enough to
40+
# upgrade their Tuple[str, int, str, Optional[str]]s to FrameSummarys.
41+
def format_list(extracted_list: Iterable[FrameSummary]) -> List[str]: ...
3942
else:
4043
def extract_tb(tb: Optional[TracebackType], limit: Optional[int] = ...) -> List[_PT]: ...
4144
def extract_stack(f: Optional[FrameType] = ...,
@@ -111,6 +114,10 @@ if sys.version_info >= (3, 5):
111114
frame_gen: Generator[Tuple[FrameType, int], None, None],
112115
*, limit: Optional[int] = ..., lookup_lines: bool = ...,
113116
capture_locals: bool = ...) -> StackSummary: ...
117+
# NOTE(https://bugs.python.org/issue34648): Authors who are diligent
118+
# enough to type-check their code are authors who are diligent enough
119+
# to upgrade their Tuple[str, int, str, Optional[str]]s to
120+
# FrameSummarys.
114121
@classmethod
115-
def from_list(cls, a_list: List[_PT]) -> StackSummary: ...
122+
def from_list(cls, a_list: Iterable[FrameSummary]) -> StackSummary: ...
116123
def format(self) -> List[str]: ...

0 commit comments

Comments
 (0)