From 2a0411b2ed3f982b0b0ad9c6ac99ee4d3210b2dc Mon Sep 17 00:00:00 2001 From: Maurice Ibrahim Date: Fri, 14 Jun 2024 12:39:04 +0200 Subject: [PATCH] added custom _string_width testing --- discord/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 99c7cfc94233..282859d5ffb9 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -71,6 +71,7 @@ import typing import warnings import logging +from cov import test, mark import yarl @@ -821,14 +822,19 @@ def has(self, element: int) -> bool: return i != len(self) and self[i] == element +@test(4) def _string_width(string: str) -> int: """Returns string's width.""" if string.isascii(): + mark(1) return len(string) - + mark(0) UNICODE_WIDE_CHAR_TYPE = 'WFA' func = unicodedata.east_asian_width - return sum(2 if func(char) in UNICODE_WIDE_CHAR_TYPE else 1 for char in string) + return sum( + 2 if (mark(2, "_string_width"), func(char))[1] in UNICODE_WIDE_CHAR_TYPE else (1, mark(2, "_string_width"))[0] + for char in string + ) class ResolvedInvite(NamedTuple):