-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defining __new__
looks cleaner than what I did for dis
. Edit: it also happens to be what the runtime does
This comment has been minimized.
This comment has been minimized.
It does however break mypy 🙃 |
This comment has been minimized.
This comment has been minimized.
hm, now I get |
This comment has been minimized.
This comment has been minimized.
We could do something similar to what I did with https://mypy-play.net/?mypy=latest&python=3.10&gist=2bdfa6f9cdc2bdd07c5d472bf4124ea5 |
This comment has been minimized.
This comment has been minimized.
On second thoughts, why don't we just mimic the runtime implementation exactly? It seems to work pretty well for Lines 324 to 333 in 7cbb579
and it would mean we could override So in the 3.11 branch we would have: 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: ... |
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
python/cpython#91531