Parse Error in SonarPython when using numeric literal separators

Steps to Reproduce:

Put a numeric constant with separators (new in Python 3.6):

MAX_AMOUNT = 9_999_999_999.99

With v1.10 of the SonarPython plugin, this produces a parse error:

85: 
86: 
--> MAX_AMOUNT = 9_999_999_999.99
87:

It’s perhaps worth noting that the popular Python code formatter Black will automatically insert these on large numeric literals.

The PEP which outlines the support of underscores in numeric literals: https://www.python.org/dev/peps/pep-0515/

Hi Adam,
Yes, I can reproduce. Of course we should improve this, ticket created SONARPY-293.
Thanks for your feedback and your help with the PEP reference :+1:
Alban

1 Like