Improve error message from os.fspath
if __fspath__
is set to None
#106046
Labels
type-feature
A feature request or enhancement
Feature or enhancement
A common Python idiom is to set a magic method to
None
in a subclass if you want to disable the behaviour that the magic method enables. If you do so, a nice error message will be given if a user tries to "call" the magic method that's been set toNone
. For example:However, Python doesn't currently do the same thing for
__fspath__
. If a subclass of anos.PathLike
sets__fspath__
toNone
, Python gives a bad error message whenos.fspath
is called on instances of that subclass:Pitch
It would be nice if Python handled
__fspath__
being set toNone
the same way it handles magic methods such as__iter__
or__hash__
being set toNone
. The error message in such cases should be theexpected str, bytes or os.PathLike object, not Baz
error message that the interpreter gives whenos.fspath
is called on an object that has no__fspath__
method at all.Linked PRs
os.fspath
if__fspath__
is set toNone
#106082The text was updated successfully, but these errors were encountered: