SF #989185: Drop unicode.iswide() and unicode.width() and add
unicodedata.east_asian_width(). You can still implement your own
simple width() function using it like this:
def width(u):
w = 0
for c in unicodedata.normalize('NFC', u):
cwidth = unicodedata.east_asian_width(c)
if cwidth in ('W', 'F'): w += 2
else: w += 1
return w
diff --git a/Lib/test/test_unicodedata.py b/Lib/test/test_unicodedata.py
index 8157fb3..0bbabb1 100644
--- a/Lib/test/test_unicodedata.py
+++ b/Lib/test/test_unicodedata.py
@@ -174,6 +174,17 @@
# The rest can be found in test_normalization.py
# which requires an external file.
+ def test_east_asian_width(self):
+ eaw = self.db.east_asian_width
+ self.assertRaises(TypeError, eaw, 'a')
+ self.assertRaises(TypeError, eaw, u'')
+ self.assertRaises(TypeError, eaw, u'ra')
+ self.assertEqual(eaw(u'\x1e'), 'N')
+ self.assertEqual(eaw(u'\x20'), 'Na')
+ self.assertEqual(eaw(u'\uC894'), 'W')
+ self.assertEqual(eaw(u'\uFF66'), 'H')
+ self.assertEqual(eaw(u'\uFF1F'), 'F')
+ self.assertEqual(eaw(u'\u2010'), 'A')
class UnicodeMiscTest(UnicodeDatabaseTest):