Skip to content

IP Interface is_unspecified broken #115766

@joeyberkovitz

Description

@joeyberkovitz

Bug report

Bug description:

from ipaddress import ip_interface

ip_interface('0.0.0.0/32').is_unspecified == False
ip_interface('0.0.0.0/32').network.is_unspecified == True
ip_interface('0.0.0.0/32').ip.is_unspecified == True

Per the documentation, the IP interface classes inherit all properties from the associated address classes. As such, is_unspecified is available as a property, although as implemented now, it will always return False for an interface.

Given that an interface is just a network and host combined, it might be reasonable for the implementation of is_unspecified to be something along the lines of self.network.is_unspecified and self.ip.is_unspecifed, possibly implemented more efficiently (for example self._ip == 0 and self._prefixlen == 32 for IPv4)

The current implementation isn't specified for an interface, so it falls back to the address implementation which checks if the address equals '0.0.0.0', although this subtly always fails because the interface equality function is used which will never return True comparing an interface and address object.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions