[Python-bugs-list] netrc module has bad error handling (PR#265)
gpk@bell-labs.com
gpk@bell-labs.com
Sun, 2 Apr 2000 23:39:40 -0400 (EDT)
Full_Name: Greg Kochanski
Version: 1.5.2
OS: Solaris 2.6
Submission from: h-135-104-50-27.research.bell-labs.com (135.104.50.27)
The constructor for netrc.netrc messes up royally
if the file named file doesn't exist.
In that case, it attempts to return None
from the constructor as an error indication,
rather than throwing an exception.
Consequently, self.hosts is not initialized,
and future attempts to use the class object will
fail. You can't usefully return a value from a
constructor.
So, the code at the top of netrc.netrc.__init__() should be
fp = open(file)
rather than
try:
fp = open(file)
except:
return None
BTW, Python ought to catch attempts to return values
from constructors.