Jason R. Coombs <jar...@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:

try:
  urllib.request.urlopen('http://api.wordnik.com/v4/word.json/foo/examples')
except urllib2.URLError as exc:
  # We caught a URLError, what's the reason?
  print(exc.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 <rep...@bugs.python.org>
<http://bugs.python.org/issue13211>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to