Repository navigation
Closed
Labels
3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = None
created_at = <Date 2013-09-25.20:55:41.793>
labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
title = 'urljoin should raise a TypeError if URL is not a string'
updated_at = <Date 2021-06-12.01:47:56.398>
user = 'https://github.com/jaraco'bugs.python.org fields:
activity = <Date 2021-06-12.01:47:56.398>
actor = 'jacobtylerwalls'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2013-09-25.20:55:41.793>
creator = 'jaraco'
dependencies = []
files = ['31876', '31889', '31933']
hgrepos = []
issue_num = 19094
keywords = ['patch']
message_count = 12.0
messages = ['198418', '198435', '198455', '198462', '198493', '198510', '198750', '198784', '198808', '230742', '386875', '395598']
nosy_count = 7.0
nosy_names = ['jaraco', 'orsenthil', 'berker.peksag', 'serhiy.storchaka', 'vajrasky', 'iritkatriel', 'jacobtylerwalls']
pr_nums = ['26687']
priority = 'normal'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue19094'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']Metadata
Metadata
Assignees
Labels
3.16new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Activity
jaraco commentedon Sep 25, 2013
That should raise a TypeError, not succeed quietly as if an empty string were passed.
vajrasky commentedon Sep 26, 2013
This is the preliminary patch to raise TypeError in that situation.
jaraco commentedon Sep 26, 2013
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:
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.
vajrasky commentedon Sep 27, 2013
What about this one?
Is this desirable? Both patches missed this case. Should we only accept str and bytes?
jaraco commentedon Sep 27, 2013
I don't mind the AttributeError - that's a reasonable exception when passing invalid types in, and that's in fact the current behavior. The example of (['a'], []) does bother me though. Those inputs are also seemingly invalid, though somewhat more compatible from a 'urljoin' perspective than two different types.
You've given me reason to re-consider your patch.
vajrasky commentedon Sep 28, 2013
I modified the patch to handle the last case using your way as well.
Anyway, I found out that urlsplit and urlparse got the same issue as well.
Same thing happens in urlsplit. Fortunately, urlunsplit and urlunparse don't have this issue.
orsenthil commentedon Oct 1, 2013
I have provided my comments in the review tool. Please check them out.
vajrasky commentedon Oct 1, 2013
Okay, attached the patch based on your comment, Senthil Kumaran. Thanks.
The reason I use isinstance to check the type is because I want to support the inheritance as much as possible.
Also, in Lib/urllib/parse.py, most of the time, we use isinstance(x, str) not type(x) == str.
But I don't know. Maybe it does not matter.
jaraco commentedon Oct 1, 2013
Vajrasky, you're right. Comparing against type(obj) is an anti-pattern. isinstance is better. Duck typing is even better (in many cases).
serhiy-storchaka commentedon Nov 6, 2014
About acceptable behavior with wrong arguments types see discussions in bpo-22766 and http://comments.gmane.org/gmane.comp.python.devel/150073 .
iritkatriel commentedon Feb 12, 2021
Still broken in 3.10:
12 remaining items
jacobtylerwalls commentedon Jul 12, 2026
The same issue was fixed for
parse_qsl()in #116897. I've updated my pull request (#26687) to follow the same approach and generalize it to the otherurllib.parsefunctions. Would anyone like to review?At the very least, adding the additional test cases would be good.
gh-63293: Reject non-string URL args and deprecate false values in ur…
pythongh-63293: Reject non-string URL args and deprecate false values…