Issue #13211: Add .reason attribute to HTTPError to implement parent class (URLError) interface.
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index e247315..7f230e2 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1318,6 +1318,17 @@
req = Request(url)
self.assertEqual(req.get_full_url(), url)
+def test_HTTPError_interface():
+ """
+ Issue 13211 reveals that HTTPError didn't implement the URLError
+ interface even though HTTPError is a subclass of URLError.
+
+ >>> err = urllib2.HTTPError(msg='something bad happened', url=None, code=None, hdrs=None, fp=None)
+ >>> assert hasattr(err, 'reason')
+ >>> err.reason
+ 'something bad happened'
+ """
+
def test_main(verbose=None):
from test import test_urllib2
test_support.run_doctest(test_urllib2, verbose)