Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:
As per the fspath PEP https://www.python.org/dev/peps/pep-0519/#c-api the below precedence is set. So for the enum inheriting from str the object itself is returned and MyEnum.RED.__str__ is used returning MyEnum.RED. You can remove inheritance from str and implement __fspath__ for your enum class to be used as per fspath protocol. > If the object is str or bytes, then allow it to pass through with an incremented refcount. If the object defines __fspath__(), then return the result of that method. All other types raise a TypeError. # bpo39081.py import os import pathlib import enum class MyEnum(enum.Enum): RED = 'red' def __fspath__(self): return self.name print(os.fspath(MyEnum.RED)) print(pathlib.Path.home() / MyEnum.RED) $ python3.8 bpo39081.py RED /Users/kasingar/RED ---------- nosy: +ethan.furman, xtreak _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39081> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com