Skip to content

Unnecessary operation in IPv4Interface and IPv6Interface #134012

Closed as not planned
@mssalvatore

Description

@mssalvatore

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)))

https://github.com/python/cpython/blob/0afbd4e42ac28240b484cabe1710fdb6c572fb1f/Lib/ipaddress.py#L1457C1-L1459

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions