Not planned
Description
The __hash__()
methods of the IPv4Interface
and IPv6Interface
classes are implemented on the main
branch as follows:
def __hash__(self):
return hash((self._ip, self._prefixlen, int(self.network.network_address)))
As best as I can figure from tracing the relevant __init__()
methods, self._ip
and int(self.network.network_address)
will always be identical. If that is so, this function could be simplified and save a few CPU cycles:
def __hash__(self):
- return hash((self._ip, self._prefixlen, int(self.network.network_address)))
+ return hash((self._ip, self._prefixlen))
Linked PRs
Metadata
Metadata
Assignees
Labels
No labels
Activity
pythongh-134012: Simplify IPv*Interface.__hash__()
mssalvatore commentedon May 15, 2025
I missed some details and the conclusion that
self._ip
andself.network.network_address
are always identical are incorrect.