-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pystac probably needs an implementation of StrEnum #265
Comments
This was just changed #261. IMO making a new base class named |
I've found it confusing to have our Enums inherit from str, and in a few cases where the auto conversion was supposed to 'just work' I found I had to make explicit casts with |
Can you give an example of this? Here's a simple example using the same implementation of from enum import Enum
class MediaType(str, Enum):
def __str__(self):
return str(self.value)
PNG = 'image/png'
assert MediaType.PNG == 'image/png' (Edit this is on Python 3.8.3) |
@kylebarron That works for my on python 3.6. |
OK, after some investigation I think this is probably user error. I believe I saw the Below is some ipython exploration that, along with your examples, convinces me that I was interpreting things incorrectly: In [8]: class Example(str, enum.Enum):
...: def __str__(self):
...: return str(self.value)
...:
...: ONE = 'one'
...: TWO = 'two'
...:
In [9]: [Example.ONE]
Out[9]: [<Example.ONE: 'one'>]
In [10]: [Example.ONE, 'two']
Out[10]: [<Example.ONE: 'one'>, 'two']
In [11]: l = [Example.ONE, 'two']
In [12]: 'one' in l
Out[12]: True
In [13]: import json
In [14]: json.dumps(l)
Out[14]: '["one", "two"]'
In [15]: 'one' in json.loads(json.dumps(l))
Out[15]: True |
Yeah I think letting |
As of #654 we have a @schwehr @kylebarron It seems to me that our |
Closed via #654 |
Just like the Enum package has
enum.IntEnum
, pystac should like have a StrEnum class. It doesn't have to be much, I since there are a bunch of them, it would be a bit cleaner.After trying it a bit, I don't think it needs any extra code.
Hmmmm... StrEnum is in python 3.10, so, maybe not. Idonno.
The text was updated successfully, but these errors were encountered: