]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-46415: Use f-string for ValueError in ipaddress.ip_{address,network,interface...
authorThomas Cellerier <thomascellerier@gmail.com>
Tue, 3 May 2022 12:12:58 +0000 (14:12 +0200)
committerGitHub <noreply@github.com>
Tue, 3 May 2022 12:12:58 +0000 (06:12 -0600)
commit52dc9c3066bcdc67a7a45d41cf158ecb1434d5f3
tree87388bf8306586e9ada724873ec5911e97352cf5
parentec8d3adb99f1ad93786fed5c1def5119b6ec73c0
bpo-46415: Use f-string for ValueError in ipaddress.ip_{address,network,interface} helper functions (#30642)

`IPv*Network` and `IPv*Interface` constructors accept a 2-tuple of
(address description, netmask) as the address parameter.
When the tuple-based address is used errors are not propagated
correctly through the `ipaddress.ip_*` helper because of the %-formatting now expecting several arguments:

In [7]: ipaddress.ip_network(("192.168.100.0", "fooo"))
        ...
TypeError: not all arguments converted during string formatting

Compared to:

In [8]: ipaddress.IPv4Network(("192.168.100.0", "foo"))
        ...
NetmaskValueError: 'foo' is not a valid netmask

Use an f-string to make sure the error is always properly formatted.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Lib/ipaddress.py
Lib/test/test_ipaddress.py
Misc/NEWS.d/next/Library/2022-01-17-16-53-30.bpo-46415.6wSYg-.rst [new file with mode: 0644]