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 xtreak
Recipients andrewni, ethan.furman, xtreak
Date 2019-12-18.07:40:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576654818.41.0.0678326938839.issue39081@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-12-18 07:40:18xtreaksetrecipients: + xtreak, ethan.furman, andrewni
2019-12-18 07:40:18xtreaksetmessageid: <1576654818.41.0.0678326938839.issue39081@roundup.psfhosted.org>
2019-12-18 07:40:18xtreaklinkissue39081 messages
2019-12-18 07:40:18xtreakcreate