This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jaraco
Recipients docs@python, jaraco, orsenthil, petri.lehtinen
Date 2011-11-08.21:39:54
SpamBayes Score 3.8262883e-06
Marked as misclassified No
Message-id <1320788395.16.0.0778504667191.issue13211@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2011-11-08 21:39:55jaracosetrecipients: + jaraco, orsenthil, docs@python, petri.lehtinen
2011-11-08 21:39:55jaracosetmessageid: <1320788395.16.0.0778504667191.issue13211@psf.upfronthosting.co.za>
2011-11-08 21:39:54jaracolinkissue13211 messages
2011-11-08 21:39:54jaracocreate