ruff icon indicating copy to clipboard operation
ruff copied to clipboard

`D102` for "inherited" docstrings.

Open WilliamJamieson opened this issue 2 years ago • 2 comments

pydocstyle code D102 is raised on any public methods that do not have a docstring. I agree with this in principle, except that I have many cases where I have a common base class which defines some method's interface (and documentation), but that method's specific implementation will be defined by child classes or needs to be modified by a child class. E.G.

class Parent:
    def foo(self, arg1, arg2, arg3):
        """Some documentation about foo."""


# possibly in a different module or package
class Child(Parent):
    def foo(self, arg1, arg2, arg3):
		return arg1 + arg2 + arg3

ruff flags foo in Child with D102, when in fact this is documented by Parent.foo.

In most cases, documenting the method in the child class would be equivalent to copy/paste of the docstring from the parent class, which I dislike. I would like the optional ability for ruff to ignore D102 on methods defined in their parent classes.

WilliamJamieson avatar Jan 31 '23 20:01 WilliamJamieson

I agree that this would be an improvement. We probably can't really support it until we start doing cross-file analysis (otherwise, it would only work if Parent and Child were defined in the same module, which seems like a minority of cases).

charliermarsh avatar Jan 31 '23 23:01 charliermarsh

I agree that this would be an improvement. We probably can't really support it until we start doing cross-file analysis

This would be a really nice thing to have for cross-file analysis. Hopefully, you can get it to work even in cases where Parent is defined outside the package being linted (i.e. if I am building of an interface defined by an external library). Though even getting it to work within just the package being linted would be a massive improvement

(otherwise, it would only work if Parent and Child were defined in the same module, which seems like a minority of cases).

Even this would be nice, as I do have code that falls into this category (although I would still have to turn it off in general).

WilliamJamieson avatar Feb 01 '23 17:02 WilliamJamieson

Would just like to mention that I would also really like to see this feature, since this is the main reason I'm not using the D rules yet. Unfortunately I'm not proficient enough in Rust to contribute to implementing it 😅

norabelrose avatar Apr 15 '23 16:04 norabelrose

It would be a nice start to ignore it in the same file, can that be implemented on short notice?

fjwillemsen avatar May 04 '23 09:05 fjwillemsen

This issue is the only drawback I am having with ruff. Everything else is better. But this is a huge problem for me.

philipp-horstenkamp avatar Oct 30 '23 11:10 philipp-horstenkamp