Uploaded image for project: 'SonarPython'
  1. SonarPython
  2. SONARPY-534

Iterable unpacking in yield and return statements no longer requires enclosing parentheses (Python 3.8)

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.8
    • Component/s: Parser
    • Labels:
      None

      Description

      Since Python 3.8, the following syntax is valid:

      >>>def parse(family):
              lastname, *members = family.split()
              return lastname.upper(), *members
      >>>parse('simpsons homer marge bart lisa sally')
      ('SIMPSONS', 'homer', 'marge', 'bart', 'lisa', 'sally')
      

      Before Python 3.8, the return expression should have been parenthesized due to the unpacking of members such as:
      return (lastname.upper(), *members)

      The same logic holds for yield expressions as well. We need to avoid parsing errors on this new syntax.

        Attachments

          Activity

            People

            Assignee:
            pierre-yves.nicolas Pierre-Yves Nicolas
            Reporter:
            guillaume.dequenne Guillaume Dequenne
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Due:
              Created:
              Updated:
              Resolved: