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.

3
  • what pylint version are you using? Commented Jul 19, 2020 at 9:35
  • I am not getting this error on pylint 2.4.4 Commented Jul 19, 2020 at 9:36
  • 1
    Your pylint thinks your python version is different than the one you are using. Commented Jul 19, 2020 at 9:47

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.