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 2013年02月09日 21:12 by thomas.scrace, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg181762 - (view) | Author: Thomas Scrace (thomas.scrace) | Date: 2013年02月09日 21:12 | |
Currently os.path.join will raise an AttributeError if passed an argument that does not have an endswith() method.
A try/except around the offending line would let us raise a more helpful TypeError:
except AttributeError as e:
bad = e.args[0].split()[0]
raise TypeError("object of type {} is not valid as a path"
"component".format(type(bad)))
|
|||
| msg181764 - (view) | Author: janzert (janzert) * | Date: 2013年02月09日 21:43 | |
While the current error message is a bit generic, I rather like that it tells you exactly why the type/object passed couldn't be used. |
|||
| msg181777 - (view) | Author: Eric V. Smith (eric.smith) * (Python committer) | Date: 2013年02月10日 01:07 | |
I think this change should not be made: it's a slippery slope, because there are thousands of places in the stdlib where a similar change could be made. It's the nature of duck typing that you're not going to get a great error message everywhere you pass in the wrong type. Python programmers just have to learn this and understand it's a source of sometimes unobvious error messages. If, despite my concerns, this change is still made, I think it is important that any new error message not mention "str", or any list of accepted types. The proposal in msg181762 is good enough: just say that whatever type was used isn't acceptable. For example: there are a number of "path object" proposals floating around, and it's possible one of those could be used with os.path.join despite it not being a str. |
|||
| msg227677 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年09月27日 14:23 | |
Fixed in issue22034. See also issue21883. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:41 | admin | set | github: 61376 |
| 2014年09月27日 14:23:28 | serhiy.storchaka | set | status: open -> closed nosy: + serhiy.storchaka messages: + msg227677 resolution: out of date stage: resolved |
| 2013年02月10日 01:07:48 | eric.smith | set | nosy:
+ eric.smith messages: + msg181777 |
| 2013年02月09日 21:43:23 | janzert | set | nosy:
+ janzert messages: + msg181764 |
| 2013年02月09日 21:12:37 | thomas.scrace | create | |