gh-153769: Clarify the TypeError from ipaddress subnet_of()/supernet_of() - #154147
Closed
fedonman wants to merge 2 commits into
Closed
gh-153769: Clarify the TypeError from ipaddress subnet_of()/supernet_of()#154147fedonman wants to merge 2 commits into
fedonman wants to merge 2 commits into
Conversation
…ernet_of() Passing something that is not a network object, such as an address, to IPv4Network.subnet_of() or supernet_of() made _is_subnet_of() reach for the network_address attribute, fail with an AttributeError, and turn that into a TypeError with a message that read like a real containment result and hid the actual cause. Check that both arguments are network objects up front and raise a clear TypeError explaining what is required, so nothing masks an internal AttributeError anymore.
An isinstance() check on _BaseNetwork rejects a network-like object that is not a subclass, which works today. Keeping the handler and suppressing the context keeps that working and still gives the caller one clear error.
Member
|
As I said, this is a premature PR. Avoid using LLMs just for getting quick contributions, especially when the issue is still under discussion. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
subnet_of()andsupernet_of()reported a non-network argument as "Unable to test subnetcontainment between ::/0 and ::1", with an
AttributeErroraboutnetwork_addressshownabove it. The message now says what is actually wrong, and the internal error is no longer
displayed:
The exception type does not change, and the handler stays. An
isinstance(_BaseNetwork)check would also reject a network-like object that is not a subclass of it, which works
today:
Nothing documents other as having to be a network instance, so that stays working here.
test_ipaddresspasses, 216 tests.