Skip to content

Commit 55738bf

Browse files
committed
Add fast paths in python_format and python_brace_format
1 parent 7a8b587 commit 55738bf

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

babel/messages/catalog.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,12 @@ def python_format(self) -> bool:
289289
290290
:type: `bool`"""
291291
ids = self.id
292-
if not isinstance(ids, (list, tuple)):
293-
ids = [ids]
294-
return any(PYTHON_FORMAT.search(id) for id in ids)
292+
if isinstance(ids, (list, tuple)):
293+
for id in ids: # Explicit loop for performance reasons.
294+
if PYTHON_FORMAT.search(id):
295+
return True
296+
return False
297+
return bool(PYTHON_FORMAT.search(ids))
295298

296299
@property
297300
def python_brace_format(self) -> bool:
@@ -304,9 +307,12 @@ def python_brace_format(self) -> bool:
304307
305308
:type: `bool`"""
306309
ids = self.id
307-
if not isinstance(ids, (list, tuple)):
308-
ids = [ids]
309-
return any(_has_python_brace_format(id) for id in ids)
310+
if isinstance(ids, (list, tuple)):
311+
for id in ids: # Explicit loop for performance reasons.
312+
if _has_python_brace_format(id):
313+
return True
314+
return False
315+
return _has_python_brace_format(ids)
310316

311317

312318
class TranslationError(Exception):

0 commit comments

Comments
 (0)