[docs] [issue13211] urllib2.HTTPError does not have 'reason' attribute.
Jason R. Coombs
report at bugs.python.org
Tue Nov 8 22:39:55 CET 2011
Jason R. Coombs <jaraco at jaraco.com> added the comment:
That was my point. If HTTPError is a subclass of URLError, then an HTTPError _is an_ URLError, and thus should implement the same public interface.
The problem is better illustrated with this request:
except urllib2.URLError as exc:
# We caught a URLError, what's the reason?
This code will fail with an attribute error, but only when the except clause catches an HTTPError (as it does in this case).
The documentation explicitly states that HTTPError is a subclass of URLError and it doesn't say anything about the addinfourl interface. The documentation strongly suggests (though implicitly) that HTTPError.reason will be present as it is with URLError.
If HTTPError does not implement the reason attribute, then there is no value in making it the subclass of URLError, and HTTPError should probably have the same parent class as URLError. However, this change is even more drastic and would almost certainly violate backward compatibility constraints.
The proposal I've made is generally backward compatible, and addresses the underlying bug (that URLError.__init__ is never called), and the symptom that a HTTPError does not implement the documented public interface.
Perhaps there's a better approach, but I believe based on the example code above, the implementation is broken.
Python tracker <report at bugs.python.org>
More information about the docs