basedmypy
basedmypy copied to clipboard
Reports `no-any-expr` for parameter-less `@pytest.fixture` annotation
Describe the problem, ie expected/actual result (if it's not blatantly obvious)
When writing tests with pytest, any method decorated with @pytest.fixture causes no-any-expr to be reported.
$ poetry run mypy .
tests/integration/test_fix.py:3:2: error: Expression type contains "Any" (has type overloaded function) [no-any-expr]
@pytest.fixture
^~~~~~~~~~~~~~
tests/integration/test_fix.py:3:2: note: See https://kotlinisland.github.io/basedmypy/_refs.html#code-no-any-expr for more info
Found 1 error in 1 file (checked 14 source files)
Adding parentheses to the decorator, e.g. when defining (autouse=True) makes the error disappear because, most likely, another overload is matched. However, using just empty parentheses makes ruff report PT001, because this style is not recommended.
This may or may not be a problem with the pytest type stubs but I'm not deep enough into typing to debug this myself.
Gist to reproduce
import pytest
@pytest.fixture
def fix() -> None:
return None
def test_fix(fix: None) -> None:
pass
Basedmypy version
basedmypy 2.6.0 (compiled: yes) Based on mypy 1.11.1
Yeah, makes me cry that I have to set ruff to prefer the parenthesis 😢
I'm certain that it's an issue with pytest stubs, not with [based]mypy, the solutions I see are:
- fix defs in pytest
- make a wrapper that is typed properly
- make some custom
Anyignoring rules where you can specify certain calls or something - make
Anys not report ifobjectcan be used instead
i know! lets reuse untyped_calls_exclude! perfect!