summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2022-09-03 17:05:56 +0100
committerda-woods <dw-git@d-woods.co.uk>2022-09-03 17:05:56 +0100
commite3882cf3885677a0dc372d46e288981ed0281869 (patch)
tree5d8547c24375234f3f547f6d0b2ea38528893fe9
parent243003ccf8dcda889118c6232452b14d30727374 (diff)
downloadcython-e3882cf3885677a0dc372d46e288981ed0281869.tar.gz
"Fix" Py2 error formatting issue
-rw-r--r--Cython/Utility/MatchCase.c7
-rw-r--r--tests/run/extra_patma_py.py14
2 files changed, 17 insertions, 4 deletions
diff --git a/Cython/Utility/MatchCase.c b/Cython/Utility/MatchCase.c
index 3f71ed1e8..08eb50433 100644
--- a/Cython/Utility/MatchCase.c
+++ b/Cython/Utility/MatchCase.c
@@ -503,8 +503,15 @@ static int __Pyx_MatchCase_CheckDuplicateKeys(PyObject *keys[], Py_ssize_t nFixe
return 0;
raise_error:
+ #if PY_MAJOR_VERSION > 2
PyErr_Format(PyExc_ValueError,
"mapping pattern checks duplicate key (%R)", key);
+ #else
+ // DW really can't be bothered working around features that don't exist in
+ // Python 2, so just provide less information!
+ PyErr_SetString(PyExc_ValueError,
+ "mapping pattern checks duplicate key");
+ #endif
bad:
Py_DECREF(var_keys_set);
return -1;
diff --git a/tests/run/extra_patma_py.py b/tests/run/extra_patma_py.py
index 0ff51e25a..182529683 100644
--- a/tests/run/extra_patma_py.py
+++ b/tests/run/extra_patma_py.py
@@ -2,6 +2,7 @@
# tag: pure3.10
import array
+import sys
def test_array_is_sequence(x):
"""
@@ -27,10 +28,15 @@ def test_duplicate_keys(key1, key2):
>>> test_duplicate_keys("a", "b")
True
- >>> test_duplicate_keys("a", "a")
- Traceback (most recent call last):
- ...
- ValueError: mapping pattern checks duplicate key ('a')
+
+ Slightly awkward doctest to work around Py2 incompatibility
+ >>> try:
+ ... test_duplicate_keys("a", "a")
+ ... except ValueError as e:
+ ... if sys.version_info[0] > 2:
+ ... assert e.args[0] == "mapping pattern checks duplicate key ('a')", e.args[0]
+ ... else:
+ ... assert e.args[0] == "mapping pattern checks duplicate key"
"""
class Keys:
KEY_1 = key1