Title: simplify overlaps function in
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Sanjay, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2019-10-01 11:43 by Sanjay, last changed 2019-10-05 12:25 by Sanjay.

File name Uploaded Description Edit
skip_broadcast_in.patch Sanjay, 2019-10-01 11:43
Pull Requests
URL Status Linked Edit
PR 16519 open Sanjay, 2019-10-01 11:45
Messages (3)
msg353676 - (view) Author: Sanjay (Sanjay) * Date: 2019-10-01 11:43
the current implementation of overlaps function tests either network or broadcast address is in other but
we can skip checking broadcast address is in other because we anyway check if other.network_address in self 

without loss of generality if we assume self has smaller prefixlen than other then when self.broadcast_address in other then other.network_address *SHOULD* be in self but the reverse is not true

so my first patch was to make the function logic simply do
`self.network_address in other or other.network_address in self`

but the current PR does a different change. We have introduced two new functions subnet_of and supernet_of

for two networks A, B there are only three possibilities 
1. they don't overlap
2. A is subnet of B
3. B is subnet of A

so we can reuse the existing function and just do
`return self.subnet_of(other) or self.supernet_of(other)`
the only thing is while overlaps() function returns false when we try to compare with a network or with diff version the other throws exception so I added a typecheck in the beginning.

P.S the docstring is slightly convoluted for newcomers, based on the three possibilities it should say "Tell if self is supernet or subnet of other" because "partly contained" can also mean two ranges intersect which can never happen to network prefixes. I have not made that change but can make it.

There are also some other issues I want to address but I want to do one at a time.
msg354004 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-10-05 12:16
What is the benefit of your version?
msg354005 - (view) Author: Sanjay (Sanjay) * Date: 2019-10-05 12:25
the version in the patch is less code a or b or c or d becomes a or d

the version in PR is using the subnet_of, supernet_of function because overlap means either a is subnet_of or supernet_of b. So was trying to consolidate the implementation of overlap from 2 to 1.
Date User Action Args
2019-10-05 12:25:55Sanjaysetmessages: + msg354005
2019-10-05 12:16:13serhiy.storchakasetmessages: + msg354004
2019-10-02 17:46:24Sanjaysetnosy: + serhiy.storchaka
2019-10-01 11:45:26Sanjaysetstage: patch review
pull_requests: + pull_request16110
2019-10-01 11:43:43Sanjaycreate