Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 59 additions & 14 deletions stdlib/inspect.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dis
import enum
import sys
import types
Expand Down Expand Up @@ -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]

class FrameInfo(NamedTuple):
frame: FrameType
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 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]: ...
Expand Down