Skip to content

Unexpected false-positive "no-value-for-parameter" from type stubs 'hidden' under 'if TYPE_CHECKING:' #8689

Open
@geokala

Description

@geokala

Bug description

This may not be a bug in pylint, so possibly can just be closed but as I just burned a bunch of time figuring it out, I'm raising it here.

When type stubs for a function that needs to be decorated are hidden under a TYPE_CHECKING, pylint seems to get unhappy with them- when they're in separate files, it can be a bit puzzling until one notices the issue is actually with the type stub.

"""Repro for issue that burned time due to 'missing arguments'.
Context: The original issue came from some async sqlalchemy fun, where the
'cake_type' was a DeclarativeBase type.
"""
# pylint: disable=too-few-public-methods
from typing import Any, Callable, TYPE_CHECKING


if TYPE_CHECKING:
    from typing_extensions import ParamSpec, TypeVar
    Params = ParamSpec('Params')
    Sometype = TypeVar('Sometype')


def add_an_arg(func: "Callable[..., Sometype]"):
    """Mutate a function, that's always fun."""
    def wrapper(self: "Base", *args: "Params.args",
                **kwargs: "Params.kwargs") -> "Sometype":
        return func(self, 'hello', *args, **kwargs)
    return wrapper


class CheeseCake:
    """A good cake."""


class Base:
    """Base repro class."""
    def __init__(self, cake_type: Any):
        self.cake_type = cake_type

    @add_an_arg
    def say_something_and_serve_cake(self, hello_arg: str, something_else: int):
        """Say something n times and return a cake."""
        for _ in range(something_else):
            print(hello_arg)
        return self.cake_type()


class CheesecakePlace(Base):
    """The subclass where the pain happens."""
    def __init__(self):
        super().__init__(CheeseCake)

    def new_customers_enter(self, num_customers: int):
        """Do the usual stuff when a new customer enters."""
        self.say_something_and_serve_cake(num_customers)

    if TYPE_CHECKING:
        def say_something_and_serve_cake(
            self, hello_arg: str, something_else: int,
        ) -> CheeseCake:
            ...

Configuration

No response

Command used

pylint --signature-mutators=add_an_arg testfile.py

Pylint output

************* Module testfile
testfile.py:47:8: E1120: No value for argument 'something_else' in method call (no-value-for-parameter)

------------------------------------------------------------------
Your code has been rated at 8.00/10 (previous run: 8.00/10, +0.00)

Expected behavior

I was expecting no complaints, but I'm not sure if that was a reasonable expectation. It might've been nice to have more indication as to where the failing function call was (as this would've immediately pointed me at the type stub), but I'm not sure how feasible that is.

Pylint version

pylint 2.17.4
astroid 2.15.5
Python 3.11.3 (main, Apr  5 2023, 14:15:06) [GCC 9.4.0]

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions