graphql-python / graphql-python/graphene-django

Cannot create enum dynamically with f-string

Open
#1,266 0 comments 0 reactions 0 assignees View on GitHub
🐛bug
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

* **What is the current behavior?**

This does not work.

```
distances_km = [1, 2, 5, 10, 20, 40, 60, 80, 100, 250, 500]
distances_with_enum_labels = [
(f'kilometre_{d}', d)
for d in distances_km
]
DistanceWithin = graphene.Enum(
'Distance Within', [(d for d in distances_with_enum_labels])
```

Error - AssertionError: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "Distance Within" does not

* **What is the expected behavior?**

It should allow this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.