55import collections
66import os
77from typing import Any , List , Optional , Union
8+ import unicodedata
89
910from . import constants
1011
@@ -110,7 +111,7 @@ def which(editor: str) -> Optional[str]:
110111
111112
112113def is_text_file (file_path : str ) -> bool :
113- """Returns if a file contains only ASCII or UTF-8 encoded text
114+ """Returns if a file contains only ASCII or UTF-8 encoded text.
114115
115116 :param file_path: path to the file being checked
116117 :return: True if the file is a text file, False if it is binary.
@@ -147,8 +148,8 @@ def is_text_file(file_path: str) -> bool:
147148
148149
149150def remove_duplicates (list_to_prune : List ) -> List :
150- """
151- Removes duplicates from a list while preserving order of the items
151+ """Removes duplicates from a list while preserving order of the items.
152+
152153 :param list_to_prune: the list being pruned of duplicates
153154 :return: The pruned list
154155 """
@@ -159,10 +160,19 @@ def remove_duplicates(list_to_prune: List) -> List:
159160 return list (temp_dict .keys ())
160161
161162
162- def alphabetical_sort (list_to_sort : List [str ]) -> List [str ]:
163+ def norm_fold (astr : str ) -> str :
164+ """Normalize and casefold Unicode strings for saner comparisons.
165+
166+ :param astr: input unicode string
167+ :return: a normalized and case-folded version of the input string
163168 """
164- Sorts a list of strings alphabetically
169+ return unicodedata .normalize ('NFC' , astr ).casefold ()
170+
171+
172+ def alphabetical_sort (list_to_sort : List [str ]) -> List [str ]:
173+ """Sorts a list of strings alphabetically.
174+
165175 :param list_to_sort: the list being sorted
166176 :return: the sorted list
167177 """
168- return sorted (list_to_sort , key = str . casefold )
178+ return sorted (list_to_sort , key = norm_fold )
0 commit comments