首页 > 解决方案 > 如何让 pylint 使用 init-hook 正确导入我的文件

问题描述

我按照这些说明如何让 pylint 使用init-hook.

但是,当我运行终端命令时,pylint server.py --rcfile=../.pylintrc我得到TypeError: expected str, bytes or os.PathLike object, not NoneType. (我认为这是因为init-hook找到 rcfile 的部分以某种方式失败,但我不确定。)

这是我.pylintrc的相关部分的文件(其余部分只是默认模板):

[MASTER]

# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=

# Specify a score threshold to be exceeded before program exits with error.
fail-under=10.0

# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS

# Add files or directories matching the regex patterns to the blacklist. The
# regex matches against base names, not paths.
ignore-patterns=

# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
# THIS GIVES THE ERROR
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"
# THIS GIVES THE SAME ERROR
# init-hook="import os, sys, pylint; sys.path.append(os.path.join(os.path.dirname(pylint.config.PYLINTRC), 'platform'))"

我怎样才能让这个 init-hook 代码正常工作?

标签: pythonpython-3.xpylintpylintrc

解决方案


推荐阅读