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 lukasz.langa
Recipients lukasz.langa
Date 2019-02-08.16:34:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1549643679.09.0.475002054663.issue35942@roundup.psfhosted.org>
In-reply-to
Content
>>> class K:
...   def __fspath__(self):
...     return 1
...
>>> import os
>>> os.stat(K())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: stat: path should be string, bytes, os.PathLike or integer, not int


This error message is internally inconsistent:
- it suggests that the error is about the path argument whereas it's in fact about the value returned from `__fspath__()`
- it hilariously states "should be integer, not int"
- it claims os.PathLike is fine as a return value from `__fspath__()` whereas it's not


I would advise removing the custom `__fspath__()` handling from `path_converter` and just directly using PyOS_FSPath which returns a valid error in this case (example from pypy3):

>>>> class K:
....   def __fspath__(self):
....     return 1
....
>>>> import os
>>>> os.open(K(), os.O_RDONLY)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: expected K.__fspath__() to return str or bytes, not int
History
Date User Action Args
2019-02-08 16:34:41lukasz.langasetrecipients: + lukasz.langa
2019-02-08 16:34:39lukasz.langasetmessageid: <1549643679.09.0.475002054663.issue35942@roundup.psfhosted.org>
2019-02-08 16:34:39lukasz.langalinkissue35942 messages
2019-02-08 16:34:38lukasz.langacreate