Skip to content

Commit 977b258

Browse files
committed
Inline distincting in catalog.py
1 parent 55738bf commit 977b258

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

babel/messages/catalog.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from babel.core import Locale, UnknownLocaleError
2424
from babel.dates import format_datetime
2525
from babel.messages.plurals import get_plural
26-
from babel.util import LOCALTZ, _cmp, distinct
26+
from babel.util import LOCALTZ, _cmp
2727

2828
if TYPE_CHECKING:
2929
from typing_extensions import TypeAlias
@@ -164,7 +164,7 @@ def __init__(
164164
if not string and self.pluralizable:
165165
string = ('', '')
166166
self.string = string
167-
self.locations = list(distinct(locations))
167+
self.locations = list(dict.fromkeys(locations)) if locations else []
168168
self.flags = set(flags)
169169
if id and self.python_format:
170170
self.flags.add('python-format')
@@ -174,12 +174,15 @@ def __init__(
174174
self.flags.add('python-brace-format')
175175
else:
176176
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)
181184
else:
182-
self.previous_id = list(previous_id)
185+
self.previous_id = []
183186
self.lineno = lineno
184187
self.context = context
185188

@@ -735,12 +738,9 @@ def __setitem__(self, id: _MessageID, message: Message) -> None:
735738
# The new message adds pluralization
736739
current.id = message.id
737740
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]))
744744
current.flags |= message.flags
745745
elif id == '':
746746
# special treatment for the header message
@@ -922,8 +922,8 @@ def _merge(message: Message, oldkey: tuple[str, str] | str, newkey: tuple[str, s
922922
assert oldmsg is not None
923923
message.string = oldmsg.string
924924

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))
927927

928928
if isinstance(message.id, (list, tuple)):
929929
if not isinstance(message.string, (list, tuple)):

0 commit comments

Comments
 (0)