Python scanner fails to parse assignments with yield expression rhs

Description

Python code using yield expressions in assignment statements causes parse errors in the SonarPython scanner

Versions

  • SonarQube 7.9 LTS
  • SonarPython 2.8 (build 6204)

Code used for reproduction

def _bar(current):
    return current

def _foo():
    x: int = 0
    y: int = yield _bar(x)
    yield x + (y if y else 0)

Error message

ERROR: Unable to parse file: repro.py
ERROR: Parse error at line 27 column 13:

   20: 
   21: 
   22: def _bar(current):
   23:     return current
   24: 
   25: def _foo():
   26:     x: int = 0
  -->      y: int = yield _bar(x)
   28:     yield x + (y if y else 0)

Potential workaround

Adding parentheses around the yield expressions

Hi @merlin-s,

Welcome to our community and thank you for reporting this bug.
I’m able to reproduce as well.
Ticket created: https://jira.sonarsource.com/browse/SONARPY-788
We plan to include a fix in the next version of our python analyzer, available in SonarQube 8.5

Thanks for the fast response!

Will the change in the scope of the bug (affecting a lot more use cases of annotated assignments) have an impact on the priority?

Also could you tell me what is the impact of a parse failure on the analysis of a python file. Will it only skip analysis of the affected statement, or will it skip the current function or even skip the analysis of the rest of the file?

Hey Merlin,

The ticket has already high priority and its fix will be part of the next version of SonarPython (i.e. 3.1), planned to be available from next week on SonarCloud and in the next version of SonarQube (end of September).

It will skip the analysis of the file having the parse error.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.