inspect: Add positions attributes that will be new in 3.11 (#7688)

This commit is contained in:
Jelle Zijlstra
2022-04-29 17:00:37 -06:00
committed by GitHub
parent 205959917b
commit 145e659482

View File

@@ -1,3 +1,4 @@
import dis
import enum
import sys
import types
@@ -459,20 +460,64 @@ def unwrap(func: Callable[..., Any], *, stop: Callable[[Any], Any] | None = ...)
# The interpreter stack
#
class Traceback(NamedTuple):
filename: str
lineno: int
function: str
code_context: list[str] | None
index: int | None # type: ignore[assignment]
if sys.version_info >= (3, 11):
class _Traceback(NamedTuple):
filename: str
lineno: int
function: str
code_context: list[str] | None
index: int | None # type: ignore[assignment]
class FrameInfo(NamedTuple):
frame: FrameType
filename: str
lineno: int
function: str
code_context: list[str] | None
index: int | None # type: ignore[assignment]
class Traceback(_Traceback):
positions: dis.Positions | None
def __new__(
cls: type[Self],
filename: str,
lineno: int,
function: str,
code_context: list[str] | None,
index: int | None,
*,
positions: dis.Positions | None = ...,
) -> Self: ...
class _FrameInfo(NamedTuple):
frame: FrameType
filename: str
lineno: int
function: str
code_context: list[str] | None
index: int | None # type: ignore[assignment]
class FrameInfo(_FrameInfo):
positions: dis.Positions | None
def __new__(
cls: type[Self],
frame: FrameType,
filename: str,
lineno: int,
function: str,
code_context: list[str] | None,
index: int | None,
*,
positions: dis.Positions | None = ...,
) -> Self: ...
else:
class Traceback(NamedTuple):
filename: str
lineno: int
function: str
code_context: list[str] | None
index: int | None # type: ignore[assignment]
class FrameInfo(NamedTuple):
frame: FrameType
filename: str
lineno: int
function: str
code_context: list[str] | None
index: int | None # type: ignore[assignment]
def getframeinfo(frame: FrameType | TracebackType, context: int = ...) -> Traceback: ...
def getouterframes(frame: Any, context: int = ...) -> list[FrameInfo]: ...