Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-100310

lupdate does not support trailing commas in Python

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.4.0 Beta1
    • 6.3.0 Alpha
    • Tools: Linguist
    • None
    • 8d4ba0a8ab (qt/qttools/dev) 8d4ba0a8ab (qt/tqtc-qttools/dev)

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

      lupdate 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. I believe the same is true if there is a comment but no pluralization.

      The problematic line is currently https://code.qt.io/cgit/qt/qttools.git/tree/src/linguist/lupdate/python.cpp#n519

      // look for comment
      if (!match(Tok_Comma) || !matchStringOrNone(comment))
          return false;
      

      The logic at currently written is that if there is a comma, there must also be a comment, and if not the extraction failed.

      Attachments

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

        Activity

          People

            kkohne Kai Köhne
            chris_hennes Chris Hennes
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes