-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
bpo-20825: Containment test for ip_network in ip_network. Patch by Michel Albert. #4065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Lib/ipaddress.py
Outdated
| return (self.network_address.is_multicast and | ||
| self.broadcast_address.is_multicast) | ||
|
|
||
| def _containment_check(self, check, other): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of switching on check, how about having something like:
@classmethod
def _is_subnet_of(cls, a, b):
# Implementation here
def subnet_of(self, other):
return self._is_subnet_of(self, other)
def supernet_of(self, other):
return self._is_subnet_of(other, self)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I made these changes, except I made is_subnet_of a staticmethod since it didn't use cls.
Lib/ipaddress.py
Outdated
| raise TypeError("{} and {} are not of the same version" | ||
| .format(a, b)) | ||
| # Dealing with another network. | ||
| if hasattr(b, 'network_address') and hasattr(b, 'broadcast_address'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since _is_subnet_of can be called both ways, you should also test the type for a.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
Note the CI failures are unrelated. An external NNTP server we use in our test suite seems to have issues... |
|
I took the liberty of making small last-minute changes. Now I'm waiting for CI results again :-) |
|
Thank you! |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Patch by Michel Albert.
https://bugs.python.org/issue20825