5

I followed these instructions on how to get pylint to import my files correctly using an init-hook.

However, when I run the terminal command pylint server.py --rcfile=../.pylintrc I get TypeError: expected str, bytes or os.PathLike object, not NoneType. (I assume this is because the part of the init-hook that finds the rcfile is somehow failing, but I'm not sure.)

Here's my .pylintrc file up to the relevant parts (the rest is just the default template):

[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'))"

How can I get this init-hook code working correctly?

Pro Q
  • 4,391
  • 4
  • 43
  • 92
  • In my environment, similar problem with using .. -- if I give the full path to the rcfile, it works. – rrauenza Nov 11 '20 at 03:08
  • 1
    That's a known bug in pylint ([#3838](https://github.com/PyCQA/pylint/issues/3838)). A workaround is to instead use `PYLINTRC=../.pylintrc pylint server.py`. – Jojo Jan 29 '21 at 10:03
  • Try something like this: https://stackoverflow.com/a/3065082 – FilBot3 Feb 09 '22 at 20:38

0 Answers0