@@ -475,44 +475,46 @@ def _extract_docstring(self, node):
475475
476476 def _extract_message (self , node ):
477477 func_name = self ._get_func_name (node )
478+ errors = []
478479 for spec in self .options .keywords .get (func_name , []):
479- if self ._extract_message_with_spec (node , spec ):
480+ err = self ._extract_message_with_spec (node , spec )
481+ if err is None :
480482 break
483+ errors .append (err )
484+ else :
485+ for err in errors :
486+ print (err , file = sys .stderr )
481487
482488 def _extract_message_with_spec (self , node , spec ):
483489 """Extract a gettext call with the given spec.
484490
485- Return True if the gettext call was successfully extracted, False
486- otherwise.
491+ Return `None` if the gettext call was successfully extracted,
492+ otherwise return an error message .
487493 """
488494 max_index = max (spec .values ())
489495 has_var_positional = any (isinstance (arg , ast .Starred ) for
490496 arg in node .args [:max_index + 1 ])
491497 if has_var_positional :
492- print (f'*** { self .filename } :{ node .lineno } : Variable positional '
493- f'arguments are not allowed in gettext calls' , file = sys .stderr )
494- return False
498+ return (f'*** { self .filename } :{ node .lineno } : Variable positional '
499+ f'arguments are not allowed in gettext calls' )
495500
496501 if max_index >= len (node .args ):
497- print (f'*** { self .filename } :{ node .lineno } : Expected at least '
498- f'{ max_index + 1 } positional argument(s) in gettext call, '
499- f'got { len (node .args )} ' , file = sys .stderr )
500- return False
502+ return (f'*** { self .filename } :{ node .lineno } : Expected at least '
503+ f'{ max_index + 1 } positional argument(s) in gettext call, '
504+ f'got { len (node .args )} ' )
501505
502506 msg_data = {}
503507 for arg_type , position in spec .items ():
504508 arg = node .args [position ]
505509 if not self ._is_string_const (arg ):
506- print (f'*** { self .filename } :{ arg .lineno } : Expected a string '
507- f'constant for argument { position + 1 } , '
508- f'got { ast .unparse (arg )} ' , file = sys .stderr )
509- return False
510+ return (f'*** { self .filename } :{ arg .lineno } : Expected a string '
511+ f'constant for argument { position + 1 } , '
512+ f'got { ast .unparse (arg )} ' )
510513 msg_data [arg_type ] = arg .value
511514
512515 lineno = node .lineno
513516 comments = self ._extract_comments (node )
514517 self ._add_message (lineno , ** msg_data , comments = comments )
515- return True
516518
517519 def _extract_comments (self , node ):
518520 """Extract translator comments.
0 commit comments