Skip to content

Unused function arguments marked with underscore _ are required to have type annotation #18911

Open
@pktiuk

Description

@pktiuk

Bug Report

Method in my class (a wrapper for mqtt library) is missing a type annotation for argument marked as unused in handler no-untyped-def

To Reproduce

class MQTTWrapper:
    @staticmethod
    def _on_connect(
        client: Client,
        userdata: "MQTTClient",
        flags: ConnectFlags,
        reason_code: paho.mqtt.reasoncodes.ReasonCode,
        _,
    ) -> None:
        pass

Expected Behavior

Annotating unused arguments does not seem to make sense.

Actual Behavior

src/mqtt.py:95: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
        def _on_connect(

Your Environment

  • Mypy version used: mypy 1.15.0 (compiled: yes)
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):

Part of pyproject.toml

[tool.mypy]
# mypy configuration: https://mypy.readthedocs.io/en/stable/config_file.html#example-pyproject-toml
# mypy settings documentation: https://mypy.readthedocs.io/en/stable/config_file.html#confval-follow_untyped_imports
follow_untyped_imports = true
strict = true # enable --strict before releasing production ready code
exclude = '(tests/.*|debug_scripts/.*)'
  • Python version used:3.12.3

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions