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.

Author ethan.furman
Recipients JelleZijlstra, brett.cannon, ethan.furman, python-dev, serhiy.storchaka
Date 2016-06-04.22:31:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1465079500.4.0.223491946064.issue27182@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-06-04 22:31:40ethan.furmansetrecipients: + ethan.furman, brett.cannon, python-dev, serhiy.storchaka, JelleZijlstra
2016-06-04 22:31:40ethan.furmansetmessageid: <1465079500.4.0.223491946064.issue27182@psf.upfronthosting.co.za>
2016-06-04 22:31:40ethan.furmanlinkissue27182 messages
2016-06-04 22:31:40ethan.furmancreate