-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
stdlib: Add several missing comparison methods #7202
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import sys | ||
from _tracemalloc import * | ||
from typing import Optional, Sequence, Union, overload | ||
from typing import Any, Optional, Sequence, Union, overload | ||
from typing_extensions import SupportsIndex | ||
|
||
def get_object_traceback(obj: object) -> Traceback | None: ... | ||
|
@@ -41,6 +41,15 @@ class Frame: | |
filename: str | ||
lineno: int | ||
def __init__(self, frame: _FrameTupleT) -> None: ... | ||
def __lt__(self, other: Frame) -> bool: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This recent change is why I used the |
||
if sys.version_info >= (3, 11): | ||
def __gt__(self, other: Frame) -> bool: ... | ||
def __ge__(self, other: Frame) -> bool: ... | ||
def __le__(self, other: Frame) -> bool: ... | ||
else: | ||
def __gt__(self, other: Frame, NotImplemented: Any = ...) -> bool: ... | ||
def __ge__(self, other: Frame, NotImplemented: Any = ...) -> bool: ... | ||
def __le__(self, other: Frame, NotImplemented: Any = ...) -> bool: ... | ||
|
||
if sys.version_info >= (3, 9): | ||
_TraceTupleT = Union[tuple[int, int, Sequence[_FrameTupleT], Optional[int]], tuple[int, int, Sequence[_FrameTupleT]]] | ||
|
@@ -69,6 +78,15 @@ class Traceback(Sequence[Frame]): | |
@overload | ||
def __getitem__(self, s: slice) -> Sequence[Frame]: ... | ||
def __len__(self) -> int: ... | ||
def __lt__(self, other: Traceback) -> bool: ... | ||
if sys.version_info >= (3, 11): | ||
def __gt__(self, other: Traceback) -> bool: ... | ||
def __ge__(self, other: Traceback) -> bool: ... | ||
def __le__(self, other: Traceback) -> bool: ... | ||
else: | ||
def __gt__(self, other: Traceback, NotImplemented: Any = ...) -> bool: ... | ||
def __ge__(self, other: Traceback, NotImplemented: Any = ...) -> bool: ... | ||
def __le__(self, other: Traceback, NotImplemented: Any = ...) -> bool: ... | ||
|
||
class Snapshot: | ||
def __init__(self, traces: Sequence[_TraceTupleT], traceback_limit: int) -> None: ... | ||
|
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.
I think we should use Counter[Any] here. It doesn't work with all Counters, only with Counters of a type that's comparable to our type. That's something we can't express in the current type system, so we should use Any.
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.
What am I missing? :)
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.
Ah right, the type parameter is the keys, but it compares the values, which are always ints.
This does make for some fun behavior:
Uh oh!
There was an error while loading. Please reload this page.
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.
Counter
s are sort of halfway betweendict
s andset
s, and the comparison methods come from theset
-like side of their personality, so it does sort of make sense if you squint at it from the right angle.