Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified os.fspath and manual check to os.fsdecode
Also changed to checking isinstance instad of trying and excepting. Although this is taking more of a LBYL than an EAFP approach, catching the TypeError was actually swallowing a potential bug. We caught TypeError before for when the obj was not a str, bytes, or os.PathLike, but this actually hid the case when the obj implemented a faulty __fspath__. os.fsdecode(x) calls x.__fspath__() and expects that to return a str or bytes, which it then decodes into a str. A type error is raised here if that __fspath__() call returned a bad type. We actually want this to be raised, since that implies a serious error in that object's __fspath__ function.
- Loading branch information