I am using pydev where I have set up pylint. The problem is that even inside the comments, pylint reports warnings. I was looking to disable any sort of checking inside any line or a block comment. Also, I wish to follow camelCase naming convention instead of underscores for variables and arguments in my code. Is there any way to specify such a rule without inserting my code with any pylint: disable comments?
-
4Please, don't use camelCase. – Burhan Khalid Apr 22 '13 at 06:59
-
8While your comment is justified, I was with a team of mainly java developers and to enhance its maintainability/acceptance, I had to stray from pythonic code. – Sumit Bisht May 02 '13 at 14:08
-
2In some cases camel case is justified. For example when using PySide or PyQt. It would just look horrible to mix Qt-ish camel case with python underscore-ish style. – HiFile.app - best file manager Dec 26 '16 at 17:06
-
2@SumitBisht the rule to trump all rules for code style is "be consistent". therefore you did the right thing :). – Trevor Boyd Smith Oct 05 '18 at 16:54
-
Yes, mixing styles is a big no and actually a sign of code smell. Maintaining consistency in any codebase is the key. – Sumit Bisht Oct 10 '18 at 10:37
6 Answers
You can globally disable warnings of a certain class using
pylint --disable=W1234
or by using a special PyLint configuration file
pylint --rcfile=/path/to/config.file
A sample config file is given below:
[MESSAGES CONTROL]
# C0111 Missing docstring
# I0011 Warning locally suppressed using disable-msg
# I0012 Warning locally suppressed using disable-msg
# W0704 Except doesn't do anything Used when an except clause does nothing but "pass" and there is no "else" clause
# W0142 Used * or * magic* Used when a function or method is called using *args or **kwargs to dispatch arguments.
# W0212 Access to a protected member %s of a client class
# W0232 Class has no __init__ method Used when a class has no __init__ method, neither its parent classes.
# W0613 Unused argument %r Used when a function or method argument is not used.
# W0702 No exception's type specified Used when an except clause doesn't specify exceptions type to catch.
# R0201 Method could be a function
# W0614 Unused import XYZ from wildcard import
# R0914 Too many local variables
# R0912 Too many branches
# R0915 Too many statements
# R0913 Too many arguments
# R0904 Too many public methods
disable=C0111,I0011,I0012,W0704,W0142,W0212,W0232,W0613,W0702,R0201,W0614,R0914,R0912,R0915,R0913,R0904,R0801
See the documentation over at Pylint's dedicated site.

- 2,776
- 2
- 17
- 25

- 3,286
- 19
- 24
-
Good answer, but there's more to it. See my answer if you want fine-grained control of pylint across multiple projects and more complex scenarios. http://stackoverflow.com/a/32672068/763269 – Chris Johnson Jan 18 '16 at 04:00
-
1I tried `pylint --disable=C0111` on the terminal and got `Usage: pylint [options] module_or_package`. Did I miss something? – Melvic Ybanez Jul 30 '16 at 13:00
-
@MelvicYbanez yes you are literally missing something ;) You have the `pylint [options]` part but not the `module_or_package` part. – C S Oct 08 '18 at 04:02
-
Links to Pylint's Official site: https://pylint.readthedocs.io/en/stable/ and GitHub repository: https://github.com/pylint-dev/pylint – YellowBlue Aug 16 '23 at 14:28
As said by cfedermann, you can specify messages to be disabled in a ~/.pylintrc
file (notice you can generate a stub file using pylint --generate-rcfile
if you don't want to use inline comments.
You'll also see in the generated file, in the [BASIC] section, options like "method-rgx", "function-rgx", etc. which you can configure as you like to support camel cases style rather than pep8 underscore style.

- 23,794
- 27
- 122
- 225

- 14,397
- 5
- 38
- 32
Although this is an old question, it should be mentioned one can now specify their own regex for matching with names.
Then your regex to match camel case would be something like:
[a-z][a-zA-Z0-9]{2,30}$

- 18,287
- 11
- 43
- 96
Here is the custom check example, and another example easier to understand.
I was facing a problem similar to you. The following code is my solution. I customized one checker to forbidden import datetime.now
. You can take it for reference :
class TestChecker(BaseChecker):
"""
find the check type in the following url:
https://github.com/PyCQA/pylint/blob/63eb8c4663a77d0caf2a842b716e4161f9763a16/pylint/checkers/typecheck.py
"""
__implements__ = IAstroidChecker
name = 'test-checker'
priority = -1
msgs = {
'W0001': (
'You should not import "%s"',
'import-datetime-returns',
'Should not import datetime'
),
}
def __init__(self, linter):
super().__init__(linter)
# I use original pylint's ImportsChecker as a property
# from import **
self.forbidden_import = ['datetime.datetime.now']
self.forbidden_import_from = ['datetime.now', 'now']
self.forbidden_import_attribute = ['datetime.now', 'now', 'datetime.datetime.now']
#the function will be rewrited
def visit_importfrom(self, node):
names = [name for name, _alias in node.names]
for item in names:
for check in self.forbidden_import_from:
if item == check:
self.add_message('W0001', node=node, args=item)
def visit_import(self, node):
names = [name for name, _ in node.names]
for item in names:
for check in self.forbidden_import:
if check == item:
self.add_message('W0001', node=node, args=item)
def visit_attribute(self, node):
for check_attr in self.forbidden_import_attribute:
if check_attr == node.as_string():
self.add_message('W0001', node=node, args=check_attr)
def register(linter):
linter.register_checker(TestChecker(linter))

- 47,830
- 31
- 106
- 135

- 943
- 10
- 12
There are two ways I customize pylint
.
Using a config file
The first way is where you
- call pylint to generate a template config file
- then you tailor the config file to your needs/wants
- then you put the config file in your the default pylint config file location or always call pylint and specify the config file path
Using a wrapper script
The second way is where you create a wrapper script that calls pylint and in the wrapper script you have a bunch of lines that look like:
pylint \
${options_here} \
--disable=xyz1 \
--disable=xyz_2 \
${more_options} \
--disable=xyz_N \
--disable=abc \
$@
Currently I am using the wrapper script approach because I want the issues to be sorted by line number and I did some shell scripting to get that sorting order.

- 18,164
- 32
- 127
- 177
Further to the above answer from pradyunsg, here is another regex for CamelCase:
^([a-z]\w+[A-Z]+\w+)
(Taken from PyLint's spelling.py
checker, found in: %APPDATA% - Local - Programs - Python - [PythonVersion] - Lib - site-packages - pylint - checkers
folder)

- 37,875
- 18
- 96
- 111