[issue39081] pathlib '/' operator does not resolve Enums with str mixin as expected

2019-12-18 Thread Ethan Furman
Ethan Furman added the comment: The other option is to continue to inherit from `str`, but override the `__str__` method: class MyEnum(str, enum.Enum): # def __str__(self): return self.value -- ___ Python tracker

[issue39081] pathlib '/' operator does not resolve Enums with str mixin as expected

2019-12-18 Thread Brett Cannon
Brett Cannon added the comment: Karthikeyan is right and this is working as expected. If you want the semantics you're after you can either implement __fspath__ as was suggested or get the 'value' attribute of the enum when constructing your path. -- nosy: +brett.cannon resolution:

[issue39081] pathlib '/' operator does not resolve Enums with str mixin as expected

2019-12-17 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan 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

[issue39081] pathlib '/' operator does not resolve Enums with str mixin as expected

2019-12-17 Thread Andrew Ni
New submission from Andrew Ni : import os import pathlib import enum class MyEnum(str, enum.Enum): RED = 'red' # this resolves to: '/Users/niandrew/MyEnum.RED' # EXPECTED: '/Users/niandrew/red' str(pathlib.Path.home() / MyEnum.RED) # this resolves to: '/Users/niandrew/red'