Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
5.15.3
-
None
Description
Python allows trailing commas inside function calls, and in particular the Black code reformatter adds these trailing commas when breaking long calls up over multiple lines. This is a particular problem for calls to translate(), which are often lengthy. What comes out of Black is something like:
translate( "AddonsInstaller", "Unable to read data from GitHub: check your internet connection and proxy settings and try again.", )
pylupdate does not extract this string, because upon seeing the comma after the text, it assumes there will then be a comment. When none is found, it acts as though it is a syntax error and stops the extraction for that line. The same is true if there is a comment but no pluralization.
The bug begins on line 650 of fetchtr.cpp (that is, in the version of pylupdate released with 5.15.3):
// look for comment if ( match(Tok_Comma) && matchStringOrNone(&com)) { // Code to handle the case where there is a comment, etc. } else { break; }
To handle the legal-in-Python trailing comma, that conditional needs to be broken up, the break statement dropped, and the string match set to disallow None:
// look for comment if (match(Tok_Comma)) { if (matchString(&com)) { // Code to handle the case where there is a comment, etc. } // No else/break here, this is legal }
A similar fix is necessary to handle a trailing comma after a comment line, in places where there is no pluralization information, and in the final case where there is plural information, but a comma before the trailing parenthesis (though I have not verified the fix for those two cases, they don't affect the codebase I'm working in).