# Sonar-scanner not able to parse python fstrings

**URL:** <https://community.sonarsource.com/t/sonar-scanner-not-able-to-parse-python-fstrings/53832>\
**Category:** SonarQube Cloud\
**Tags:** python, sonarqube-cloud, scanner\
**Created:** [November 26, 2021, 2:01pm UTC](https://community.sonarsource.com/t/sonar-scanner-not-able-to-parse-python-fstrings/53832 "2021-11-26T14:01:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tmiple](https://avatars.discourse-cdn.com/v4/letter/t/ad7895/32.png) [@Tmiple](https://community.sonarsource.com/u/Tmiple)\
**Post date:** [November 26, 2021, 2:01pm UTC](https://community.sonarsource.com/t/sonar-scanner-not-able-to-parse-python-fstrings/53832/1 "2021-11-26T14:01:02Z")

</div>

- Versions used (SonarQube, Scanner, Plugin, and any relevant extension)
  - sonar-scanner: 4.6.2.2472

- Error observed (wrap logs/code around triple quote ``` for proper formatting)
  - `Couldn't parse '/home/.../internet_monitor.py' as Python source: 'invalid syntax' at line 72`
  - Content of the line: `print(f'No internet')`

- Steps to reproduce
  - Analyse a python file with such content

- Potential workaround
  - Do not use format strings?

- In case of SonarCloud:
  - ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
    - Bitbucket

  - CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI, Jenkins, other)
    - Bitbucket pipelines

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [November 26, 2021, 2:29pm UTC](https://community.sonarsource.com/t/sonar-scanner-not-able-to-parse-python-fstrings/53832/2 "2021-11-26T14:29:39Z")

</div>

Hey there.

I had no trouble analyzing a file with just this line

`print(f'No internet')`

[test.py.zip](https://community.sonarsource.com/uploads/short-url/nDOVwkA7wkMurWHVntGLaRv1FVA.zip) (214 Bytes)

Does such a file analyze successfully for you? If so, can you provide a more detailed reproducer?

---

<div class="post-metadata">

**Author:** ![Tmiple](https://avatars.discourse-cdn.com/v4/letter/t/ad7895/32.png) [@Tmiple](https://community.sonarsource.com/u/Tmiple)\
**Post date:** [November 26, 2021, 2:47pm UTC](https://community.sonarsource.com/t/sonar-scanner-not-able-to-parse-python-fstrings/53832/3 "2021-11-26T14:47:20Z")

</div>

Our whole CI system takes a while. Do you have a simple test to verify operation using `sonar-scanner`?

---

<div class="post-metadata">

**Author:** ![Tmiple](https://avatars.discourse-cdn.com/v4/letter/t/ad7895/32.png) [@Tmiple](https://community.sonarsource.com/u/Tmiple)\
**Post date:** [November 26, 2021, 3:03pm UTC](https://community.sonarsource.com/t/sonar-scanner-not-able-to-parse-python-fstrings/53832/4 "2021-11-26T15:03:38Z")

</div>

Alright, one step further. I can analyse files with `print(f'No internet')` in it.

But not when coverage tests have been ran against these files. Disabling python coverage fixes the analysis.

Would you mind trying with coverage?

---

<div class="post-metadata">

**Author:** ![Andrea\_Guarino](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/andrea_guarino/32/54797_2.png) [@Andrea\_Guarino](https://community.sonarsource.com/u/Andrea_Guarino)\
**Post date:** [November 26, 2021, 3:47pm UTC](https://community.sonarsource.com/t/sonar-scanner-not-able-to-parse-python-fstrings/53832/5 "2021-11-26T15:47:16Z")

</div>

Hi @Tmiple ,  
Are you sure this is coming from `sonar-scanner`? Python analyzer doesn’t do any parsing related to coverage: it just reads the provided coverage file.

The error message seems coming from [coverage tool](https://github.com/nedbat/coveragepy/blob/1c29ef3e4b871508bb2defd6b47b9a745547b626/coverage/parser.py#L350) instead. Since f-string have been introduced from Python 3.6 , can you double check what Python version is used in your CI environment?

---

<div class="post-metadata">

**Author:** ![Tmiple](https://avatars.discourse-cdn.com/v4/letter/t/ad7895/32.png) [@Tmiple](https://community.sonarsource.com/u/Tmiple)\
**Post date:** [November 29, 2021, 7:45am UTC](https://community.sonarsource.com/t/sonar-scanner-not-able-to-parse-python-fstrings/53832/6 "2021-11-29T07:45:01Z")

</div>

That is very well spotted! Turns out the issue was there. The logging from our CI was not synchonous it seems. Leading me to blame sonar-scanner.

Appologies!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [December 6, 2021, 7:45am UTC](https://community.sonarsource.com/t/sonar-scanner-not-able-to-parse-python-fstrings/53832/7 "2021-12-06T07:45:02Z")

</div>

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