aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'pypy/objspace/std/unicodeobject.py')
-rw-r--r--pypy/objspace/std/unicodeobject.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
index b9a212183a..a89047cd16 100644
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -42,13 +42,10 @@ class W_UnicodeObject(W_Root):
self._length = length
self._index_storage = rutf8.null_storage()
if not we_are_translated():
- try:
- # best effort, too expensive to handle surrogates
- ulength = rutf8.codepoints_in_utf(utf8str)
- except:
- ulength = length
- assert ulength == length
-
+ # utf8str must always be a valid utf8 string, except maybe with
+ # explicit surrogate characters---which .decode('utf-8') doesn't
+ # special-case in Python 2, which is exactly what we want here
+ assert length == len(utf8str.decode('utf-8'))
@staticmethod