basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

support pytest

Open KotlinIsland opened this issue 1 year ago • 6 comments

pylance:

from pytest import fixture

@fixture()
def f() -> int:
    return 1


def test_asdf(f):
    reveal_type(f)  # Any

This is of course absolutely insane that it's Any.

I don't know the best way to handle this, via a plugin?

KotlinIsland avatar Apr 18 '24 00:04 KotlinIsland

blocked by #22

i dont want to special-case specific modules if i can help it, especially 3rd party ones, so i don't really want to do this without a plugin system

DetachHead avatar Apr 18 '24 01:04 DetachHead

With pytest 8.3.2 and bpr 1.16.0 I get Type of "f" is "int" with

from pytest import fixture
from typing_extensions import reveal_type


@fixture()
def f() -> int:
    return 1


def test_asdf(f: int):
    reveal_type(f)

so no Anymore 🤷🏻‍♂️

jorenham avatar Aug 14 '24 12:08 jorenham

sorry the example in the original post is a bit confusing. this part with the type annotation in backticks was just pseudocode we came up with to say that it should infer f as int and show it as an inlay hint:

def test_asdf(f`: int`):
    reveal_type(f)

i updated that example to remove that part because i don't think this is really relevant to inlay hints. the inlay hint support is implied (as in, once we have pytest support and f gets inferred as int, the inlay hint will come naturally)

@fixture()
def f() -> int:
    return 1


def test_asdf(f): # no type annotation should be needed, it should just infer it as int
    reveal_type(f) # int

DetachHead avatar Aug 14 '24 13:08 DetachHead

once #336 is resolved we also want to disable reportUnusedParameter on pytest hookspecs (related: https://github.com/astral-sh/ruff/issues/9803)

DetachHead avatar Aug 17 '24 08:08 DetachHead