Skip to content

Commit ec9542a

Browse files
committed
Micro-optimizat TypeVarId.__hash__
1 parent 3b2c5f1 commit ec9542a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mypy/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ class TypeVarId:
543543
# function type variables.
544544

545545
# Metavariables are allocated unique ids starting from 1.
546-
raw_id: int
546+
raw_id: Final[int]
547547

548548
# Level of the variable in type inference. Currently either 0 for
549549
# declared types, or 1 for type inference metavariables.
@@ -586,7 +586,7 @@ def __ne__(self, other: object) -> bool:
586586
return not (self == other)
587587

588588
def __hash__(self) -> int:
589-
return hash((self.raw_id, self.meta_level, self.namespace))
589+
return self.raw_id ^ (self.meta_level << 8) ^ hash(self.namespace)
590590

591591
def is_meta_var(self) -> bool:
592592
return self.meta_level > 0

0 commit comments

Comments
 (0)