1

When I do pylint main.py, I get the following error:

E: 7, 0: invalid syntax (<string>, line 7) (syntax-error)

# main.py

import os

repo = os.environ.get('GITHUB_REPOSITORY')
branch = os.environ.get('GITHUB_REF')
commit = os.environ.get('GITHUB_SHA')

commit_url = f'https://github.com/{repo}/commit/{commit}'
repo_url = f'https://github.com/{repo}/tree/{branch}'

print(commit_url, repo_url)

The code is running as expected but pylint is giving this strange error. I am using Python 3.6.9 on Ubuntu 18.04.

Ravgeet Dhillon
  • 532
  • 2
  • 6
  • 24

2 Answers2

3

It looks like PyLint isn't happy with your f-strings (introduced in 3.6) and is validating against the syntax of an older Python version. I'd check whether the PyLint you are using is running from the same Python environment your Python you are running the program with. I would guess it's running from your system Python, while your program is running from a virtual environment.

With pylint 2.5.3 and Python 3.8.2 the only complaint PyLint makes is about the lack of a module docstring.

************* Module main
main.py:1:0: C0114: Missing module docstring (missing-module-docstring)

-----------------------------------
Your code has been rated at 8.57/10
rbanffy
  • 2,319
  • 1
  • 16
  • 27
0

Use .format method like below

import os

repo = os.environ.get('GITHUB_REPOSITORY')
branch = os.environ.get('GITHUB_REF')
commit = os.environ.get('GITHUB_SHA')

commit_url = 'https://github.com/{}/commit/{}'.format(repo, commit)
repo_url = 'https://github.com/{}/tree/{}'.format(repo, branch)

print(commit_url, repo_url)

Check here, Python 3 returns "invalid syntax" when trying to perform string interpolation

Vignesh
  • 1,553
  • 1
  • 10
  • 25
  • 1
    They aren't getting an actual syntax error, rather, the linter is reporting an error that is incorrect. Also, if you are going to link to another answer, then you should vote to close as a duplicate, not write an answer that is just the same as the linked answer – juanpa.arrivillaga Jul 19 '20 at 09:46