pylint
pylint copied to clipboard
Improve error message of the ``spelling-dict`` option
Bug description
Cannot apply pylint to files in parent- and sub-folders using bash CLI.
Command used
pylint src/packages/ics/plugins/
Pylint output
Traceback (most recent call last):
File "C:\Users\andreas.luckert\.pyenv\pyenv-win\versions\3.9.4\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\andreas.luckert\.pyenv\pyenv-win\versions\3.9.4\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\andreas.luckert\Projects\proj-venv\Scripts\pylint.exe\__main__.py", line 7, in <module>
File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\__init__.py", line 24, in run_pylint
PylintRun(sys.argv[1:])
File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\lint\run.py", line 324, in __init__
linter.load_config_file()
File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option_manager_mixin.py", line 321, in load_config_file
self.global_set_option(option, value)
File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option_manager_mixin.py", line 189, in global_set_option
self._all_options[opt].set_option(opt, value)
File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\options_provider_mixin.py", line 54, in set_option
value = _validate(value, optdict, optname)
File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 115, in _validate
return _call_validator(_type, optdict, name, value)
File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 96, in _call_validator
return VALIDATORS[opttype](optdict, option, value)
File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 83, in <lambda>
"choice": lambda opt, name, value: _choice_validator(opt["choices"], name, value),
File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 31, in _choice_validator
raise optparse.OptionValueError(msg % (name, value, choices))
optparse.OptionValueError: option spelling-dict: invalid value: 'en_US', should be in ['']
Expected behavior
Linting all files within the given directory.
Pylint version
PYLINTHOME is now 'C:\Users\andreas.luckert\AppData\Local\pylint\pylint\Cache' but obsolescent 'C:\Users\andreas.luckert\.pylint.d' is found; you can safely remove the latter
pylint 2.11.1
astroid 2.8.0
Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)]
OS / Environment
Windows 10
Related
I've already filed this issue on StackOverFlow
Do you have a pylintrc file? If so, could you paste it here?
I've just checked the whereabouts of my pylintrc files:
./.cache/pre-commit/repo0iwlpid1/.pylintrc
./.cache/pre-commit/repo0v23xj4q/.pylintrc
./.cache/pre-commit/repo8bzi95iu/examples/pylintrc
./.cache/pre-commit/repo8bzi95iu/examples/pylintrc_camelcase
./.cache/pre-commit/repo8bzi95iu/pylintrc
./.cache/pre-commit/repo8bzi95iu/tests/functional/d/disabled_msgid_in_pylintrc.py
./.cache/pre-commit/repo8bzi95iu/tests/functional/d/disabled_msgid_in_pylintrc.rc
./.cache/pre-commit/repo8bzi95iu/tests/regrtest_data/.pylintrc
./.cache/pre-commit/repo8bzi95iu/tests/regrtest_data/comments_pylintrc
./.cache/pre-commit/repo8bzi95iu/tests/regrtest_data/test_pylintrc_comments.py
./.cache/pre-commit/repokqe4_938/examples/pylintrc
./.cache/pre-commit/repokqe4_938/examples/pylintrc_camelcase
./.cache/pre-commit/repokqe4_938/pylintrc
./.cache/pre-commit/repokqe4_938/tests/functional/d/disabled_msgid_in_pylintrc.py
./.cache/pre-commit/repokqe4_938/tests/functional/d/disabled_msgid_in_pylintrc.rc
./.cache/pre-commit/repokqe4_938/tests/regrtest_data/.pylintrc
./.cache/pre-commit/repokqe4_938/tests/regrtest_data/comments_pylintrc
./.cache/pre-commit/repokqe4_938/tests/regrtest_data/test_pylintrc_comments.py
./.cache/pre-commit/repoltjy0ux6/examples/pylintrc
./.cache/pre-commit/repoltjy0ux6/examples/pylintrc_camelcase
./.cache/pre-commit/repoltjy0ux6/pylintrc
./.cache/pre-commit/repoltjy0ux6/tests/functional/d/disabled_msgid_in_pylintrc.py
./.cache/pre-commit/repoltjy0ux6/tests/functional/d/disabled_msgid_in_pylintrc.rc
./.cache/pre-commit/repoltjy0ux6/tests/regrtest_data/.pylintrc
./.cache/pre-commit/repoltjy0ux6/tests/regrtest_data/comments_pylintrc
./.cache/pre-commit/repoltjy0ux6/tests/regrtest_data/test_pylintrc_comments.py
./.cache/pre-commit/repoozydvb7d/examples/pylintrc
./.cache/pre-commit/repoozydvb7d/examples/pylintrc_camelcase
./.cache/pre-commit/repoozydvb7d/pylintrc
./.cache/pre-commit/repoozydvb7d/tests/functional/d/disabled_msgid_in_pylintrc.py
./.cache/pre-commit/repoozydvb7d/tests/functional/d/disabled_msgid_in_pylintrc.rc
./.cache/pre-commit/repoozydvb7d/tests/regrtest_data/.pylintrc
./.cache/pre-commit/repoozydvb7d/tests/regrtest_data/comments_pylintrc
./.cache/pre-commit/repoozydvb7d/tests/regrtest_data/test_pylintrc_comments.py
./.cache/pre-commit/repot7yxyz2x/pylintrc
....
Thus, I picked the very first one in the list: pylintrc.txt
Hope its content will help you along.
Hm, that file seems to be fine.
I would expect a pylintrc file with a line:
spelling-dict=en_US or spelling-dict="en_US"
If that's not the case then something else is trying to set spelling-dict which would require some additional investigation.
Could this be the culprit?:
[pylint.spelling]
spelling-dict = en_US
spelling-private-dict-file = .dictionary
I found it in 'setup.cfg' inside the project's parent directory.
Yeah, that is most definitely it 😄
I'm looking at the code and trying to solve this, but I don't know what this setting is supposed to do.
Do you know if you have installed the python-enchant package? Or if it is supposed to be installed in your environment? According to the code it might be necessary for this setting to work correctly.
I didn't have installed the pyenchant package.
Now, after installing it, it works indeed:
$ pip install pyenchant
Collecting pyenchant
Using cached pyenchant-3.2.1-py3-none-win_amd64.whl (11.9 MB)
Installing collected packages: pyenchant
Successfully installed pyenchant-3.2.1
$ pylint src/packages/ics/plugins/
************* Module ics.plugins.ics_account_de
src\packages\ics\plugins\ics_account_de.py:514:0: R0902: Too many instance attributes (11/7) (too-many-instance-attributes)
************* Module ics.plugins.ics_frequency
src\packages\ics\plugins\ics_frequency.py:226:53: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
-----------------------------------
Your code has been rated at 9.99/10
I guess we should work on the error code here. I'm going to change the title to something actionable that we can work towards!
I'm having a similar issue with this. running with this in pylintrc spelling-dict=en-US or even spelling-dict=en_US I always get
usage: pylint [options]
pylint: error: argument --spelling-dict: invalid choice: 'en-US' (choose from '')
same behavior if I run this via command line with --spelling-dict=en
and yes I do have pyenchant installed. What could be the issue here?
You do not have any local dict available for pyenchant (probably). The error message need to be different when the choices are an empty list.
Ah, seems like it would be good to link users to https://pyenchant.github.io/pyenchant/install.html in case of this failure. I didn't realize I needed more than just pip installing.
Ok I ran brew install enchant and that solved my issue which I think is probably the same as the original issue. I'm not sure updating this instr = " To make it work, install the 'python-enchant' package." to include the url above is sufficient because this instr doesn't seem to be hit?
Let's not couple our message with something too precise about pyenchant that we do not control. 'check your pyenchant installation in particular system dependencies' will still be right if pyenchant change URL and installation methods.