From 65947e35fe8cd5afb5d8044b9416e0d628f75a83 Mon Sep 17 00:00:00 2001 From: Bar Harel Date: Mon, 13 Dec 2021 14:07:07 +0200 Subject: [PATCH 1/3] fix TypeError --- Lib/ipaddress.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index e601f6f476e4dfb..41b74b040c180aa 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -52,7 +52,7 @@ def ip_address(address): pass raise ValueError('%r does not appear to be an IPv4 or IPv6 address' % - address) + (address,)) def ip_network(address, strict=True): @@ -82,7 +82,7 @@ def ip_network(address, strict=True): pass raise ValueError('%r does not appear to be an IPv4 or IPv6 network' % - address) + (address,)) def ip_interface(address): @@ -117,7 +117,7 @@ def ip_interface(address): pass raise ValueError('%r does not appear to be an IPv4 or IPv6 interface' % - address) + (address,)) def v4_int_to_packed(address): From 34504591c7b8f78c4705f43c9a3ea514bffda2ac Mon Sep 17 00:00:00 2001 From: Bar Harel Date: Tue, 21 Dec 2021 00:55:20 +0200 Subject: [PATCH 2/3] use f strings --- Lib/ipaddress.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 41b74b040c180aa..ad79ba106db5a72 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -51,8 +51,8 @@ def ip_address(address): except (AddressValueError, NetmaskValueError): pass - raise ValueError('%r does not appear to be an IPv4 or IPv6 address' % - (address,)) + raise ValueError(f'{address!r} does not appear to be an IPv4 or ' + f'IPv6 address') def ip_network(address, strict=True): @@ -81,8 +81,8 @@ def ip_network(address, strict=True): except (AddressValueError, NetmaskValueError): pass - raise ValueError('%r does not appear to be an IPv4 or IPv6 network' % - (address,)) + raise ValueError(f'{address!r} does not appear to be an IPv4 or ' + f'IPv6 network') def ip_interface(address): @@ -116,8 +116,8 @@ def ip_interface(address): except (AddressValueError, NetmaskValueError): pass - raise ValueError('%r does not appear to be an IPv4 or IPv6 interface' % - (address,)) + raise ValueError(f'{address!r} does not appear to be an IPv4 or ' + f'IPv6 interface') def v4_int_to_packed(address): From 9422adf4466e7713fc1d721c13e2792732eee2f8 Mon Sep 17 00:00:00 2001 From: Bar Harel Date: Tue, 21 Dec 2021 01:22:41 +0200 Subject: [PATCH 3/3] news --- .../next/Library/2021-12-21-01-22-33.bpo-46141.ilGn6L.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-12-21-01-22-33.bpo-46141.ilGn6L.rst diff --git a/Misc/NEWS.d/next/Library/2021-12-21-01-22-33.bpo-46141.ilGn6L.rst b/Misc/NEWS.d/next/Library/2021-12-21-01-22-33.bpo-46141.ilGn6L.rst new file mode 100644 index 000000000000000..25c2e2030ac823f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-12-21-01-22-33.bpo-46141.ilGn6L.rst @@ -0,0 +1,3 @@ +Fix :func:`~ipaddress.ip_network`, :func:`~ipaddress.ip_address` and +:func:`~ipaddress.ip_interface` to throw a correct error if a tuple is +passed. Fix by Bar Harel.