使用 Pylint 时出现无效语法错误,但代码运行正常
Getting invalid syntax error when using Pylint but code runs fine
当我执行 pylint main.py
时,出现以下错误:
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)
代码如预期的那样 运行 但 pylint 给出了这个奇怪的错误。我在 Ubuntu 18.04.
上使用 Python 3.6.9
使用如下的 .format 方法
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)
点这里,
看起来 PyLint 对您的 f 字符串(在 3.6 中引入)不满意,并且正在根据旧 Python 版本的语法进行验证。我会检查您使用的 PyLint 是否来自 Python 与您的 Python 程序相同的 运行 环境。我猜它是来自您的系统 Python 的 运行,而您的程序是来自虚拟环境的 运行。
对于 pylint 2.5.3 和 Python 3.8.2,PyLint 唯一的抱怨是缺少模块文档字符串。
************* Module main
main.py:1:0: C0114: Missing module docstring (missing-module-docstring)
-----------------------------------
Your code has been rated at 8.57/10
当我执行 pylint main.py
时,出现以下错误:
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)
代码如预期的那样 运行 但 pylint 给出了这个奇怪的错误。我在 Ubuntu 18.04.
上使用 Python 3.6.9使用如下的 .format 方法
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)
点这里,
看起来 PyLint 对您的 f 字符串(在 3.6 中引入)不满意,并且正在根据旧 Python 版本的语法进行验证。我会检查您使用的 PyLint 是否来自 Python 与您的 Python 程序相同的 运行 环境。我猜它是来自您的系统 Python 的 运行,而您的程序是来自虚拟环境的 运行。
对于 pylint 2.5.3 和 Python 3.8.2,PyLint 唯一的抱怨是缺少模块文档字符串。
************* Module main
main.py:1:0: C0114: Missing module docstring (missing-module-docstring)
-----------------------------------
Your code has been rated at 8.57/10