econchick / interrogate

Explain yourself! Interrogate a codebase for docstring coverage.
https://interrogate.readthedocs.io
MIT License
562 stars 46 forks source link

Add `ignore-typing-overload` option #152

Closed barseghyanartur closed 3 months ago

barseghyanartur commented 1 year ago

Describe the feature you'd like

Consider the following example:


from typing import overload, Literal

class MyClass:
    @overload
    def something(self, raw=Literal[True]) -> bytes:
        ...

    @overload
    def something(self, raw=Literal[False]) -> str:
        ...

    def something(self, raw: bool = False) -> bytes | str:
        """My method that does something"""
        pass

It should be totally valid to have only final method documented and the first two methods to be totally blank on documentation.

Is your feature request related to a problem?

Incorrect documented/undocumented ratio.

Your Environment

Additional context

So, just having something like this (default - False), would do the job:

[tool.interrogate]
# ...
ignore-typing-overload = true
# ...
thomaspinder commented 1 year ago

Hey, is there an update on this? Would love to see this functionality!

Lucas-Steinmann commented 8 months ago

I also came here, since I'm interested in an option to ignore methods decorated with @override. Although, if I'm not mistaken, the example given above does not represent a valid use of @override.

@override, as it was just added in Python 3.12, allows explicitly marking a method in a subclass as an override of a method in a superclass. See: https://peps.python.org/pep-0698/.

What the initial comment describes looks to me something like an "overload" of a method. Although I doubt that this would actually work without any third party libraries.

A better example would be:

from typing import override

class Parent:
    def foo(self) -> int:
        """My docstring, which I only want to write once for the whole class hierarchy."""
        return 1

class Child(Parent):
    @override
    def foo(self) -> int:
        return 2
barseghyanartur commented 8 months ago

What a good catch. The overload is what I actually meant. Somehow, it was transformed into override. The code (corrected) is how it actually works in Python.

I also came here, since I'm interested in an option to ignore methods decorated with @override. Although, if I'm not mistaken, the example given above does not represent a valid use of @override.

@override, as it was just added in Python 3.12, allows explicitly marking a method in a subclass as an override of a method in a superclass. See: https://peps.python.org/pep-0698/.

What the initial comment describes looks to me something like an "overload" of a method. Although I doubt that this would actually work without any third party libraries.

A better example would be:

from typing import override

class Parent:
    def foo(self) -> int:
        """My docstring, which I only want to write once for the whole class hierarchy."""
        return 1

class Child(Parent):
    @override
    def foo(self) -> int:
        return 2
econchick commented 3 months ago

Hey folks - check out 1.6.0 released today with -O / --ignore-overloaded-functions / ignore-overloaded-functions = false. Let me know if you have issues!