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 berker.peksag, jaraco, vajrasky
Date 2013-09-26.22:59:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1380236391.59.0.302020038673.issue19094@psf.upfronthosting.co.za>
In-reply-to
Content
Thanks Vajraski for the patch (especially the tests).

A colleague reminded me of an aphorism by Raymond Hettinger from the recent PyCon paraphrased: duck typing is superior to isinstance.

Maybe instead consider something like this:

diff -r 7f13d5ecf71f Lib/urllib/parse.py
--- a/Lib/urllib/parse.py	Sun Sep 22 09:33:45 2013 -0400
+++ b/Lib/urllib/parse.py	Thu Sep 26 18:52:18 2013 -0400
@@ -405,10 +405,9 @@
 def urljoin(base, url, allow_fragments=True):
     """Join a base URL and a possibly relative URL to form an absolute
     interpretation of the latter."""
-    if not base:
-        return url
-    if not url:
-        return base
+    if not base or not url:
+        # one of the inputs is empty, so simply concatenate
+        return base + url
     base, url, _coerce_result = _coerce_args(base, url)
     bscheme, bnetloc, bpath, bparams, bquery, bfragment = \
             urlparse(base, '', allow_fragments)

This implementation is not only shorter and raises TypeErrors if the types aren't compatible, but those errors are triggered by the underlying implementation. Furthermore, if either the url or base were to be a duck-type that met the necessary interface, it need not be a string subclass.

I don't feel strongly either way, but I'm slightly more inclined to accept the simpler implementation. I'm interested in the everyone's thoughts on either approach.
History
Date User Action Args
2013-09-26 22:59:51jaracosetrecipients: + jaraco, berker.peksag, vajrasky
2013-09-26 22:59:51jaracosetmessageid: <1380236391.59.0.302020038673.issue19094@psf.upfronthosting.co.za>
2013-09-26 22:59:51jaracolinkissue19094 messages
2013-09-26 22:59:51jaracocreate