Skip to content

Commit 6052128

Browse files
committed
Use utf8 c_string_encoding
Switch the Cython c_string_encoding directive from "ascii" to "utf8" so implicit char* <-> str conversions (e.g. av.Dictionary options, FFmpeg error strings) no longer raise UnicodeDecode/EncodeError on non-ASCII data.
1 parent 2f80cad commit 6052128

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def parse_cflags(raw_flags):
163163

164164
compiler_directives = {
165165
"c_string_type": "str",
166-
"c_string_encoding": "ascii",
166+
"c_string_encoding": "utf8",
167167
"embedsignature": True,
168168
"binding": False,
169169
"language_level": 3,

tests/test_dictionary.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ def test_dictionary() -> None:
1515
assert d.pop("key") == "value"
1616
pytest.raises(KeyError, d.pop, "key")
1717
assert len(d) == 0
18+
19+
20+
def test_dictionary_non_ascii() -> None:
21+
d = Dictionary()
22+
d["café"] = "naïve 日本語 🎵"
23+
24+
assert d["café"] == "naïve 日本語 🎵"
25+
assert "café" in d
26+
assert list(d) == ["café"]

0 commit comments

Comments
 (0)