Issue 35942: posixmodule.c:path_converter() returns an invalid exception message for broken PathLike objects (original) (raw)

class K: ... def fspath(self): ... return 1 ... import os os.stat(K()) Traceback (most recent call last): File "", line 1, in TypeError: stat: path should be string, bytes, os.PathLike or integer, not int

This error message is internally inconsistent:

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 "", line 1, in TypeError: expected K.fspath() to return str or bytes, not int