[issue46415] ipaddress.ip_{address, network, interface} raise TypeError instead of ValueError if given a tuple as address

2022-01-17 Thread Thomas Cellerier


New submission from Thomas Cellerier :

`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 Traceback (most recent call 
last)
 in 
> 1 ipaddress.ip_network(("192.168.100.0", "fooo"))

/usr/lib/python3.8/ipaddress.py in ip_network(address, strict)
 81 pass
 82
---> 83 raise ValueError('%r does not appear to be an IPv4 or IPv6 
network' %
 84  address)
 85

TypeError: not all arguments converted during string formatting

Compared to:

In [8]: ipaddress.IPv4Network(("192.168.100.0", "foo"))

---
NetmaskValueError Traceback (most recent call 
last)
 in 
> 1 ipaddress.IPv4Network(("192.168.100.0", "foo"))

/usr/lib/python3.8/ipaddress.py in __init__(self, address, strict)
   1453
   1454 self.network_address = IPv4Address(addr)
-> 1455 self.netmask, self._prefixlen = self._make_netmask(mask)
   1456 packed = int(self.network_address)
   1457 if packed & int(self.netmask) != packed:

/usr/lib/python3.8/ipaddress.py in _make_netmask(cls, arg)
   1118 # Check for a netmask or hostmask in 
dotted-quad form.
   1119 # This may raise NetmaskValueError.
-> 1120 prefixlen = cls._prefix_from_ip_string(arg)
   1121 netmask = 
IPv4Address(cls._ip_int_from_prefix(prefixlen))
   1122 cls._netmask_cache[arg] = netmask, prefixlen

/usr/lib/python3.8/ipaddress.py in _prefix_from_ip_string(cls, ip_str)
516 ip_int = cls._ip_int_from_string(ip_str)
517 except AddressValueError:
--> 518 cls._report_invalid_netmask(ip_str)
519
520 # Try matching a netmask (this would be /1*0*/ as a 
bitwise regexp).

/usr/lib/python3.8/ipaddress.py in _report_invalid_netmask(cls, 
netmask_str)
472 def _report_invalid_netmask(cls, netmask_str):
473 msg = '%r is not a valid netmask' % netmask_str
--> 474 raise NetmaskValueError(msg) from None
475
476 @classmethod

NetmaskValueError: 'foo' is not a valid netmask

--
components: Library (Lib)
messages: 410798
nosy: thomascellerier
priority: normal
severity: normal
status: open
title: ipaddress.ip_{address,network,interface} raise TypeError instead of 
ValueError if given a tuple as address
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue46415>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46415] ipaddress.ip_{address, network, interface} raise TypeError instead of ValueError if given a tuple as address

2022-01-17 Thread Thomas Cellerier


Change by Thomas Cellerier :


--
keywords: +patch
pull_requests: +28845
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30642

___
Python tracker 
<https://bugs.python.org/issue46415>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46415] ipaddress.ip_{address, network, interface} raises TypeError instead of ValueError if given a tuple as address

2022-01-17 Thread Thomas Cellerier


Change by Thomas Cellerier :


--
title: ipaddress.ip_{address,network,interface} raise TypeError instead of 
ValueError if given a tuple as address -> 
ipaddress.ip_{address,network,interface} raises TypeError instead of ValueError 
if given a tuple as address

___
Python tracker 
<https://bugs.python.org/issue46415>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com