Not planned
Description
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
Activity
sterliakov commentedon Apr 11, 2025
This is not a deficiency in
mypy
,_
variable is not special in typing contexts.I'd recommend annotating
_: object
explicitly. I see some merit in ignoring missing type hints on_
params, but suspect it's a rare case that doesn't warrant additional effort, especially given that the "principled" approach of annotating asobject
is an acceptable workaround.hauntsaninja commentedon May 30, 2025
Yes, users may also want to do
_: Never
or other variants