homepage

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.

classification
Title: Posix os.path.join should raise TypeError when passed unusable type
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, janzert, serhiy.storchaka, terry.reedy, thomas.scrace
Priority: normal Keywords:

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:41adminsetgithub: 61376
2014年09月27日 14:23:28serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg227677

resolution: out of date
stage: resolved
2013年02月10日 01:07:48eric.smithsetnosy: + eric.smith
messages: + msg181777
2013年02月09日 21:43:23janzertsetnosy: + janzert
messages: + msg181764
2013年02月09日 21:12:37thomas.scracecreate

AltStyle によって変換されたページ (->オリジナル) /