econchick/interrogate

Add `ignore-typing-overload` option

Closed this issue ยท 4 comments

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

  • interrogate version(s) (interrogate --version: 1.5.0
  • Operating System(s): Linux
  • Python version(s): 3.10

Additional context

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

[tool.interrogate]
# ...
ignore-typing-overload = true
# ...

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

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

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

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!