Skip to content

Commit 9a19447

Browse files
authored
Use unidecode to handle unicode characters in constant names (#1080)
1 parent 55a03ba commit 9a19447

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

graphene/utils/str_converters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from unidecode import unidecode
23

34

45
# Adapted from this response in Stackoverflow
@@ -18,4 +19,4 @@ def to_snake_case(name):
1819

1920

2021
def to_const(string):
21-
return re.sub(r"[\W|^]+", "_", string).upper() # noqa
22+
return re.sub(r"[\W|^]+", "_", unidecode(string)).upper()

graphene/utils/tests/test_str_converters.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ def test_camel_case():
2121

2222
def test_to_const():
2323
assert to_const('snakes $1. on a "#plane') == "SNAKES_1_ON_A_PLANE"
24+
25+
26+
def test_to_const_unicode():
27+
assert to_const("Skoða þetta unicode stöff") == "SKODA_THETTA_UNICODE_STOFF"

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def run_tests(self):
8686
"graphql-core>=3.0.0,<4",
8787
"graphql-relay>=3.0.0,<4",
8888
"aniso8601>=6,<9",
89+
"unidecode>=1.1.1,<2",
8990
],
9091
tests_require=tests_require,
9192
extras_require={"test": tests_require, "dev": dev_requires},

0 commit comments

Comments
 (0)