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.
Created on 2012年07月17日 08:11 by chris.jerdonek, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| nicer-error-for-none.diff | hynek, 2012年07月17日 09:46 | |||
| nicer-error-for-none-v2.diff | hynek, 2012年07月17日 10:50 | |||
| Messages (7) | |||
|---|---|---|---|
| msg165685 - (view) | Author: Chris Jerdonek (chris.jerdonek) * (Python committer) | Date: 2012年07月17日 08:11 | |
The error message for os.path.join() is misleading when the first argument is None. The message should probably say something about mixing "None" and strings. Python 3.3.0b1 (default:f954ee489896, Jul 16 2012, 22:42:29) [GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin >>> import os >>> os.path.join(None, 'a') Traceback (most recent call last): File "<stdin>", line 1, in <module> File ".../cpython/Lib/posixpath.py", line 89, in join "components.") from None TypeError: Can't mix strings and bytes in path components. |
|||
| msg165694 - (view) | Author: Hynek Schlawack (hynek) * (Python committer) | Date: 2012年07月17日 09:46 | |
I propose the following patch (against 3.2) that does the right thing. |
|||
| msg165696 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2012年07月17日 10:25 | |
I'd be more inclined to tighten up the check for the "can't mix" message to something like:
valid_types = all(isinstance(s, (str, bytes, bytearray)) for s in (a, ) + p)
if valid_types:
# Must have a mixture of text and binary data
raise TypeError("Can't mix strings and bytes in path components.")
raise
If people pass in something that isn't a valid argument *at all*, then I'm fine with just letting the underlying exception pass through.
The str/bytes case is just worth special-casing because either on their own *are* valid arguments.
|
|||
| msg165703 - (view) | Author: Hynek Schlawack (hynek) * (Python committer) | Date: 2012年07月17日 10:50 | |
Yeah, we talked about that exact think with Antoine on IRC. New proposal. |
|||
| msg165704 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2012年07月17日 10:54 | |
Looks good to me |
|||
| msg165706 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年07月17日 11:10 | |
New changeset 5553a53a230a by Hynek Schlawack in branch '3.2': #15377: Make posixpath.join() more strict when checking for str/bytes mix http://hg.python.org/cpython/rev/5553a53a230a New changeset d087ef80372d by Hynek Schlawack in branch 'default': #15377: Make posixpath.join() more strict when checking for str/bytes mix http://hg.python.org/cpython/rev/d087ef80372d |
|||
| msg165707 - (view) | Author: Hynek Schlawack (hynek) * (Python committer) | Date: 2012年07月17日 11:11 | |
Fine! :) |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:32 | admin | set | github: 59582 |
| 2012年07月17日 11:11:41 | hynek | set | status: open -> closed resolution: fixed messages: + msg165707 stage: patch review -> resolved |
| 2012年07月17日 11:10:56 | python-dev | set | nosy:
+ python-dev messages: + msg165706 |
| 2012年07月17日 10:54:24 | ncoghlan | set | messages: + msg165704 |
| 2012年07月17日 10:50:27 | hynek | set | files:
+ nicer-error-for-none-v2.diff messages: + msg165703 |
| 2012年07月17日 10:25:48 | ncoghlan | set | messages: + msg165696 |
| 2012年07月17日 09:49:24 | hynek | set | assignee: hynek versions: + Python 3.2 |
| 2012年07月17日 09:46:05 | hynek | set | files:
+ nicer-error-for-none.diff nosy: + ncoghlan, pitrou messages: + msg165694 keywords: + patch stage: patch review |
| 2012年07月17日 08:15:29 | hynek | set | nosy:
+ hynek |
| 2012年07月17日 08:11:57 | chris.jerdonek | create | |