Intrastellar Explorer
Intrastellar Explorer

Reputation: 2411

PyCharm: how to disable Missing docstring inspection locally

Question

I have a method in a Python class that I use functools.wraps to assign a docstring. Here is the exact code I use:

facade.py

#!/usr/bin/env python3

"""Facade."""


from functools import wraps

import back_end


@wraps(back_end.some_method)
def renamed_method(str_to_print):  # noinspection PyMissingOrEmptyDocstring
    back_end.some_method(str_to_print)

back_end.py

#!/usr/bin/env python3


"""Back End."""


def some_method(some_str: str) -> None:
    """Prints out a string.

    Args:
        some_str: A string to print

    """
    print(some_str)

PyCharm inspection warns Missing docstring on the method renamed_method. This is what it looks like on my end:

What I Can See

I added # pylint: disable=C0111 to the same line, and it does not make the warning go away.

How can I make this warning go away? I do not want to uncheck the inspection globally.


What I Have Tried

FYI, I use PyCharm CE 2018.3.7. I also just updated to PyCharm CE 2019.2.2 and got the same results. I use the default settings, only things I have changed are using Google docstring format and checking all inspection options for Python.

#1: Lightbulb --> Suppression Option

I looked at this answer: https://stackoverflow.com/a/51148355/11163122

Also documented on PyCharm's website here.

And I don't get the suppression options it promises.

Pressing on light bulb

#2: noinspection comment

I also tried: # noinspection PyMissingOrEmptyDocstring (full list here). Here is the full attempt:

@wraps(back_end.some_method)
def renamed_method(str_to_print):  # noinspection PyMissingOrEmptyDocstring
    back_end.some_method(str_to_print)

And an image of what I am seeing:

noinspection output


Aside

Why do I use the functools.wraps decorator? See facade pattern.

Upvotes: 2

Views: 3534

Answers (1)

Grismar
Grismar

Reputation: 31329

PyCharm allows you to suppress (instead of disable) the inspection.

You can click the lightbulb and select 'suppress for this class' or add this manually:

# noinspection PyMissingOrEmptyDocstring

More here https://www.jetbrains.com/help/pycharm/disabling-and-enabling-inspections.html#suppress-inspections

Specific to the example as given, this won't work:

@wraps(back_end.some_method)
def renamed_method(str_to_print):  # noinspection PyMissingOrEmptyDocstring
    back_end.some_method(str_to_print)

But this will:

# noinspection PyMissingOrEmptyDocstring
@wraps(back_end.some_method)
def renamed_method(str_to_print):
    back_end.some_method(str_to_print)

Upvotes: 2

Related Questions