[New-bugs-announce] [issue29913] ipadress compare_networks does not work according to documentation

Sanjay report at bugs.python.org
Mon Mar 27 03:23:35 EDT 2017


New submission from Sanjay:

according to the docs compare_networks only checks the network address but the implementation is also taking the mask length into account. It returns '0' only if both the network address and the mask are equal but this can be done with just equality check ( ip1 == ip2 )

Example:
>>> ip1=ipaddress.ip_network("1.1.1.0/24")
>>> ip2=ipaddress.ip_network("1.1.1.0/25")
>>> ip1.compare_networks(ip2)
-1
>>> ip1 == ip2
False
>>> ip1.network_address
IPv4Address('1.1.1.0')
>>> ip2.network_address
IPv4Address('1.1.1.0')
>>> 

shouldn't we ignore the mask length ? I have tried it here:

https://github.com/s-sanjay/cpython/commit/942073c1ebd29891e047b5e784750c2b6f74494a

----------
components: Library (Lib)
messages: 290566
nosy: Sanjay
priority: normal
severity: normal
status: open
title: ipadress compare_networks does not work according to documentation
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29913>
_______________________________________


More information about the New-bugs-announce mailing list