Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1799

pylupdate does not support trailing commas

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Out of scope
    • Affects Version/s: 5.15.3
    • Fix Version/s: None
    • Component/s: Tooling
    • Labels:
      None
    • Platform/s:
      All

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

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            crmaurei Cristian Maureira-Fredes
            Reporter:
            chris_hennes Chris Hennes
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes