From 7d84a322afb129045b5c82790bad56b7d7f4fbc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 5 Aug 2021 06:59:00 +0200 Subject: Add ``disable-next`` option (#4797) * Add ``disable-next`` option Adding `# pylint: disable-next=msgid` to your file will disable the message for the next line. This closes #1682 * Add documentation, rorganize the FAQ for disable/enable and add ref to the full doc Co-authored-by: Pierre Sassoulas --- doc/faq.rst | 16 ++++++++++++---- doc/user_guide/message-control.rst | 15 +++++++++++++++ doc/whatsnew/2.10.rst | 4 ++++ 3 files changed, 31 insertions(+), 4 deletions(-) (limited to 'doc') diff --git a/doc/faq.rst b/doc/faq.rst index d679bc286..02e252457 100644 --- a/doc/faq.rst +++ b/doc/faq.rst @@ -123,12 +123,20 @@ Much probably. Read :ref:`ide-integration` 4.1 How to disable a particular message? ----------------------------------------------------------- -Add "#pylint: disable=some-message,another-one" at the desired block level -or at the end of the desired line of code. - -A block is either a scope (say a function, a module), or a multiline statement (Try, Finally, if statements, for loops). +For a single line : Add ``#pylint: disable=some-message,another-one`` at the +end of the desired line of code. Since Pylint 2.10 you can also use +``#pylint: disable-next=...`` on the line just above the problem. +``...`` in the following example is a short hand for the list of +messages you want to disable. + +For larger disable : You can add ``#pylint: disable=...`` at the block level to +disable for the block. It's possible to enable for the reminder of the block +with ``#pylint: enable=...`` A block is either a scope (say a function, a module), +or a multiline statement (try, finally, if statements, for loops). `It's currently impossible to disable inside an else block`_ +Read :ref:`message-control` for details and examples. + .. _`It's currently impossible to disable inside an else block`: https://github.com/PyCQA/pylint/issues/872 4.2 Is there a way to disable a message for a particular module only? diff --git a/doc/user_guide/message-control.rst b/doc/user_guide/message-control.rst index 217b1b556..dafbe2af4 100644 --- a/doc/user_guide/message-control.rst +++ b/doc/user_guide/message-control.rst @@ -39,6 +39,13 @@ The pragma controls can disable / enable: a, b = ... # pylint: disable=unbalanced-tuple-unpacking +* All the violations on the following line + + .. sourcecode:: python + + # pylint: disable-next=unbalanced-tuple-unpacking + a, b = ... + * All the violations in a single scope .. sourcecode:: python @@ -179,6 +186,14 @@ Here's an example with all these rules in a single place: print(self.bla) print(self.blop) + def meth9(self): + """test next line disabling""" + # no error + # pylint: disable-next=no-member + print(self.bla) + # error + print(self.blop) + Detecting useless disables -------------------------- diff --git a/doc/whatsnew/2.10.rst b/doc/whatsnew/2.10.rst index de209d5d2..6622c20fa 100644 --- a/doc/whatsnew/2.10.rst +++ b/doc/whatsnew/2.10.rst @@ -71,6 +71,10 @@ Other Changes Closes #626 +* Add ``disable-next`` option: allows using `# pylint: disable-next=msgid` to disable a message for the following line + + Closes #1682 + * Added ``format-string-without-interpolation`` checker: Emitted when formatting is applied to a string without any variables to be replaced Closes #4042 -- cgit v1.2.1