Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing-function-docstring when overriding methods of generic classes with undefined type parameters #9766

Open
JulianJvn opened this issue Jul 3, 2024 · 0 comments
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling

Comments

@JulianJvn
Copy link

JulianJvn commented Jul 3, 2024

Bug description

Pylint doesn't give missing-function-docstring messages for methods that @override base class methods that have docstrings. This is good.

Unfortunately, this doesn't seem to work if the base class is generic and pylint can't resolve the type parameter. So there is a missing-function-docstring message given in this case.

An example where this happens is protobuf: The Python code generated by protobuf doesn't have the classes in it, instead they are generated at runtime. (The protobuf compiler protoc is able to generate *.pyi files with type stubs of the class definition, but due to #6281 pylint is not able to resolve them.)

Here is some example code to reproduce it without protobuf:

"""Repro code."""
# pylint: disable=undefined-variable
import abc
from typing import Generic, override, TypeVar
T = TypeVar("T")

class AbstractClass(abc.ABC, Generic[T]):
    """Abstract class."""
    @abc.abstractmethod
    def method(self) -> T:
        """Abstract method."""

class Subclass(AbstractClass[foo]):
    """Concrete class."""
    @override
    def method(self) -> foo:
        return 42

When working with protobuf, substitute for example MyProtoFile_pb2.MyMessage for foo, where MyProtoFile_pb2 is the module generated by protoc. The MyMessage member is only generated at runtime, so instead of undefined-variable you have to disable no-member (but this issue is not about that). The missing-function-docstring error is the same, and I assume also the cause.

I'm able to suppress the no-member messages with ignored-modules, but how do I get rid of the missing-function-docstring messages?

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:16:4: C0116: Missing function or method docstring (missing-function-docstring)

Expected behavior

No messages.

Pylint version

pylint 3.2.5
astroid 3.2.2
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]

OS / Environment

No response

Additional dependencies

No response

@JulianJvn JulianJvn added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling
Projects
None yet
Development

No branches or pull requests

1 participant