-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Another two micro-optimizations #19633
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 3 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 |
---|---|---|
|
@@ -5,18 +5,7 @@ | |
import sys | ||
from abc import abstractmethod | ||
from collections.abc import Iterable, Sequence | ||
from typing import ( | ||
TYPE_CHECKING, | ||
Any, | ||
ClassVar, | ||
Final, | ||
NamedTuple, | ||
NewType, | ||
TypeVar, | ||
Union, | ||
cast, | ||
overload, | ||
) | ||
from typing import TYPE_CHECKING, Any, ClassVar, Final, NewType, TypeVar, Union, cast, overload | ||
from typing_extensions import Self, TypeAlias as _TypeAlias, TypeGuard | ||
|
||
import mypy.nodes | ||
|
@@ -1607,11 +1596,25 @@ def bound(self) -> bool: | |
return bool(self.items) and self.items[0].is_bound | ||
|
||
|
||
class FormalArgument(NamedTuple): | ||
name: str | None | ||
pos: int | None | ||
typ: Type | ||
required: bool | ||
class FormalArgument: | ||
def __init__(self, name: str | None, pos: int | None, typ: Type, required: bool) -> None: | ||
self.name = name | ||
self.pos = pos | ||
self.typ = typ | ||
self.required = required | ||
|
||
def __eq__(self, other: object) -> bool: | ||
if not isinstance(other, FormalArgument): | ||
return NotImplemented | ||
return ( | ||
self.name == other.name | ||
and self.pos == other.pos | ||
and self.typ == other.typ | ||
and self.required == other.required | ||
) | ||
|
||
def __hash__(self) -> int: | ||
return hash((self.name, self.pos, self.typ, self.required)) | ||
Comment on lines
+1599
to
+1617
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. Would a dataclass work here? According to the docs, the dataclass decorator is supported for native classes. https://mypyc.readthedocs.io/en/latest/native_classes.html#class-decorators Not sure what the performance difference is though. 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 is true that dataclasses are extension, but looking at generated C, their constructor still uses 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. Would 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. No, not that dictionary :-) The one to pack keyword arguments to constructor. Anyway, just to be sure, I tried that, and (as expected) neither changed the constructor calling logic (which is there I guess because constructor is auto-generated not by us). |
||
|
||
|
||
class Parameters(ProperType): | ||
|
Uh oh!
There was an error while loading. Please reload this page.