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 <rep...@bugs.python.org>
<http://bugs.python.org/issue29913>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to