Using the standard enum.Enum causes TypeError
See original GitHub issueI’m getting the following errors when I try to use the vanilla enum in Python 3.6 + graphene 2.0.dev20170802065539:
class KernelStatus(enum.Enum):
PREPARING = 10
RUNNING = 30
...
class ComputeSession(graphene.ObjectType):
status = graphene.Enum.from_enum(KernelStatus)
...
class Query(graphene.ObjectType):
compute_sessions = graphene.List(ComputeSession,
access_key=graphene.String(required=True),
status=graphene.Enum.from_enum(KernelStatus))
...
Error during initialization:
File "/Users/joongi/Projects/Lablup/sorna-gateway/sorna/gateway/admin.py", line 92, in <module>
class Query(graphene.ObjectType):
File "/Users/joongi/Projects/Lablup/sorna-gateway/venv/lib/python3.6/site-packages/graphene/utils/subclass_with_meta.py", line 40, in __init_subclass__
super_class.__init_subclass_with_meta__(**options)
File "/Users/joongi/Projects/Lablup/sorna-gateway/venv/lib/python3.6/site-packages/graphene/types/objecttype.py", line 39, in __init_subclass_with_meta__
yank_fields_from_attrs(base.__dict__, _as=Field)
File "/Users/joongi/Projects/Lablup/sorna-gateway/venv/lib/python3.6/site-packages/graphene/types/utils.py", line 31, in yank_fields_from_attrs
field = get_field_as(value, _as)
File "/Users/joongi/Projects/Lablup/sorna-gateway/venv/lib/python3.6/site-packages/graphene/types/utils.py", line 21, in get_field_as
return _as.mounted(value)
File "/Users/joongi/Projects/Lablup/sorna-gateway/venv/lib/python3.6/site-packages/graphene/types/mountedtype.py", line 20, in mounted
**unmounted.kwargs
File "/Users/joongi/Projects/Lablup/sorna-gateway/venv/lib/python3.6/site-packages/graphene/types/field.py", line 53, in __init__
self.args = to_arguments(args or OrderedDict(), extra_args)
File "/Users/joongi/Projects/Lablup/sorna-gateway/venv/lib/python3.6/site-packages/graphene/types/argument.py", line 41, in to_arguments
extra_args = sorted(extra_args.items(), key=lambda f: f[1])
TypeError: '<' not supported between instances of 'EnumMeta' and 'String'
So, is there no way to use the standard enum.Enum
class in Python 3?
Or am I missing something?
I need to use the vanilla one because I share the same enum type with a user-defined TypeDecorator in SQLAlchemy core.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
enum — Support for enumerations — Python 3.11.1 ...
In Python 3.12 it will be possible to check for member values and not just members; until then, a TypeError will be raised...
Read more >Associating string representations with an Enum that uses ...
It seems that the issue is that an Enum will use all class variables as the enum values, which causes them to return...
Read more >Build Enumerations of Constants With Python's Enum
In this tutorial, you'll learn how to: Create enumerations of constants using Python's Enum class; Work with enumerations and their members in ...
Read more >enum – Enumeration Type — PyMOTW 3
Members with repeated values trigger a ValueError exception when the Enum class is being interpreted. $ python3 enum_unique_enforce.py Traceback ...
Read more >Python Enumeration
Python provides you with the enum module that contains the Enum type for ... to assign a new member to the Color enumeration...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @achimnol, you will need to initialize the Enum (or wrap on a Field) when using it:
I also came across this bug. Why does graphene try to sort the arguments by the argument value (
f[1]
), instead of the argument name (f[0]
)? https://github.com/graphql-python/graphene/blob/0a54094f59e1b1bca83e4574dbb35587536bbce6/graphene/types/argument.py#L79