diff -r 23beb7f8561a Lib/ipaddress.py --- a/Lib/ipaddress.py Fri Jun 29 15:12:54 2012 +0300 +++ b/Lib/ipaddress.py Fri Jun 29 10:49:58 2012 -0700 @@ -1249,7 +1249,8 @@ return # Constructing from a packed address - if isinstance(address, bytes) and len(address) == 4: + if (not isinstance(address, str) and + isinstance(address, bytes) and len(address) == 4): self._ip = struct.unpack('!I', address)[0] return @@ -1860,7 +1861,8 @@ return # Constructing from a packed address - if isinstance(address, bytes) and len(address) == 16: + if (not isinstance(address, str) and + isinstance(address, bytes) and len(address) == 16): tmp = struct.unpack('!QQ', address) self._ip = (tmp[0] << 64) | tmp[1] return diff -r 23beb7f8561a Lib/test/test_ipaddress.py --- a/Lib/test/test_ipaddress.py Fri Jun 29 15:12:54 2012 +0300 +++ b/Lib/test/test_ipaddress.py Fri Jun 29 10:49:58 2012 -0700 @@ -106,6 +106,8 @@ AssertInvalidIP(":1:2:3:4:5:6:7") AssertInvalidIP("1:2:3:4:5:6:7:") AssertInvalidIP(":1:2:3:4:5:6:") + AssertInvalidIP("1000") + AssertInvalidIP("1000000000000000") self.assertRaises(ipaddress.AddressValueError, ipaddress.IPv4Interface, '')