__init__ does not gracefully handle getting NoneType via eq
vicenteg opened this issue · 1 comments
vicenteg commented
Probably should return a ValueError, or some such when init is passed None?
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
> > > from ipcalc import *
> > > ip = IP(u'10.157.199.130/25')
> > > ip in [ None ]
> > > Traceback (most recent call last):
> > > File "<stdin>", line 1, in <module>
> > > File "/Library/Python/2.7/site-packages/ipcalc.py", line 351, in **eq**
> > > return long(self) == long(IP(other))
> > > File "/Library/Python/2.7/site-packages/ipcalc.py", line 156, in **init**
> > > if '/' in ip:
> > > TypeError: argument of type 'NoneType' is not iterable```
gandaro commented
I think it is just fine like that. You already get a TypeError… Also, you should not force an argument to be of a specific type.
>>> from ipcalc import *
>>> ip = IP('10.157.199.130/25')
>>> ip in [None]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/ipcalc.py", line 351, in __eq__
return long(self) == long(IP(other))
File "/Library/Python/2.7/site-packages/ipcalc.py", line 156, in __init__
if '/' in ip:
TypeError: argument of type 'NoneType' is not iterable