Skip to content

Keyword arguments of __call__ are not interpreted correctly #3241

@Sterbic

Description

@Sterbic

I looks like mypy drops all keyword arguments of the __call__ function of a class and recognises only positional arguments.

Code example:

class Formatter:
    def __call__(
        self,
        message: str,
        *,  # same behaviour with and without 
        bold: bool = False,
    ) -> str:
        if bold:
            message = f"** {message} **"
        return message

formatter = Formatter()
print(formatter("test", bold=True))

Mypy error:
test.py:13: error: Unexpected keyword argument "bold" for "__call__" of "Formatter"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions