23
23
from babel .core import Locale , UnknownLocaleError
24
24
from babel .dates import format_datetime
25
25
from babel .messages .plurals import get_plural
26
- from babel .util import LOCALTZ , _cmp , distinct
26
+ from babel .util import LOCALTZ , _cmp
27
27
28
28
if TYPE_CHECKING :
29
29
from typing_extensions import TypeAlias
@@ -164,7 +164,7 @@ def __init__(
164
164
if not string and self .pluralizable :
165
165
string = ('' , '' )
166
166
self .string = string
167
- self .locations = list (distinct (locations ))
167
+ self .locations = list (dict . fromkeys (locations )) if locations else []
168
168
self .flags = set (flags )
169
169
if id and self .python_format :
170
170
self .flags .add ('python-format' )
@@ -174,12 +174,15 @@ def __init__(
174
174
self .flags .add ('python-brace-format' )
175
175
else :
176
176
self .flags .discard ('python-brace-format' )
177
- self .auto_comments = list (distinct (auto_comments ))
178
- self .user_comments = list (distinct (user_comments ))
179
- if isinstance (previous_id , str ):
180
- self .previous_id = [previous_id ]
177
+ self .auto_comments = list (dict .fromkeys (auto_comments )) if auto_comments else []
178
+ self .user_comments = list (dict .fromkeys (user_comments )) if user_comments else []
179
+ if previous_id :
180
+ if isinstance (previous_id , str ):
181
+ self .previous_id = [previous_id ]
182
+ else :
183
+ self .previous_id = list (previous_id )
181
184
else :
182
- self .previous_id = list ( previous_id )
185
+ self .previous_id = []
183
186
self .lineno = lineno
184
187
self .context = context
185
188
@@ -735,12 +738,9 @@ def __setitem__(self, id: _MessageID, message: Message) -> None:
735
738
# The new message adds pluralization
736
739
current .id = message .id
737
740
current .string = message .string
738
- current .locations = list (distinct (current .locations +
739
- message .locations ))
740
- current .auto_comments = list (distinct (current .auto_comments +
741
- message .auto_comments ))
742
- current .user_comments = list (distinct (current .user_comments +
743
- message .user_comments ))
741
+ current .locations = list (dict .fromkeys ([* current .locations , * message .locations ]))
742
+ current .auto_comments = list (dict .fromkeys ([* current .auto_comments , * message .auto_comments ]))
743
+ current .user_comments = list (dict .fromkeys ([* current .user_comments , * message .user_comments ]))
744
744
current .flags |= message .flags
745
745
elif id == '' :
746
746
# special treatment for the header message
@@ -922,8 +922,8 @@ def _merge(message: Message, oldkey: tuple[str, str] | str, newkey: tuple[str, s
922
922
assert oldmsg is not None
923
923
message .string = oldmsg .string
924
924
925
- if keep_user_comments :
926
- message .user_comments = list (distinct (oldmsg .user_comments ))
925
+ if keep_user_comments and oldmsg . user_comments :
926
+ message .user_comments = list (dict . fromkeys (oldmsg .user_comments ))
927
927
928
928
if isinstance (message .id , (list , tuple )):
929
929
if not isinstance (message .string , (list , tuple )):
0 commit comments