Jason R. Coombs added the comment: 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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19094> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com