Python parser failing on word "print"

Hi, Sonarsource community!

  • Sonarqube community 7.7.0.23042 on Linux
  • Postgresql 11
  • Analysis done on Windows 10

When running analysis on my sqlalchemy models file the parser is failing with the following error.

ERROR: Unable to parse file: *******************************************/models.py
ERROR: Parse error at line 70 column 10:

   67: 'UNIQUE', String)
   68:     totalAmount = Column('TOTAL_AMT', CustomNumber('{:010.2f}'))
   69:     totalGST = Column('TOTAL_GST', CustomNumber('{:010.2f}'))
  -->      print = Column('PD_PRINT', CustomNumber('{:d}'))
   71:     run = Column('RUN', String)
   72:     zone = Column('ZONE', String)
   73:     deliveryInstructions

When I change the word print, the parser succeeds. I am unable to rename the column permanently as that has a flow-on effect to many other processes and functions of the entire project. I am also able to use other sqlalchemy tools to avoid the issue but I don’t feel like this is a valid reason to keep the code in my project.

    print2 = Column('PD_PRINT', CustomNumber('{:d}'))

    # TODO: This is a hack to allow for the sonarqube scanner to process the file
    # It fails to parse on the word "print"
    @property
    def dict(self):
        temp = super(_Order, self).dict
        temp['print'] = self.print2

        return temp

    @hybrid_property
    def print(self):
        return self.print2

Any suggestions for fixing this or will it need to be addressed in the sonarqube software?

Hi!

This is a problem in our parser which tries to support both Python 2 and Python 3.
We should definitely fix it.
I created SONARPY-334 to track that issue.

Thanks a lot for your feedback!

Thank you!