Message267335
Currently, os.fspath will raise an exception if the thing passed in is not str/bytes/PathLike, and that error message will proclaim that str or bytes or PathLike is required; however, this is not true in cases such as Path (which doesn't allow bytes), and incomplete in cases such as os.open (which also allows ints).
On the other hand, if the thing has a functional __fspath__ (meaning calling it doesn't raise an exception) then os.fspath will return whatever that method returns, which could be complete garbage.
So os.fspath is being too strict, too open, and too lax all at the same time.
Given Guido's reluctance to check the output of __fspath__(), plus the current difficulty of painless integration with existing functions, I think we should have os.fspath() only raise an exception if obj.__fspath__ exists and calling it raises an exception, otherwise we return the result of calling obj.__fspath__(), or obj if it doesn't have __fspath__.
In case that wasn't clear, attached is a unit test that passes when the above changes are implemented. |
|
Date |
User |
Action |
Args |
2016-06-04 22:31:40 | ethan.furman | set | recipients:
+ ethan.furman, brett.cannon, python-dev, serhiy.storchaka, JelleZijlstra |
2016-06-04 22:31:40 | ethan.furman | set | messageid: <1465079500.4.0.223491946064.issue27182@psf.upfronthosting.co.za> |
2016-06-04 22:31:40 | ethan.furman | link | issue27182 messages |
2016-06-04 22:31:40 | ethan.furman | create | |
|