Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support pytest #311

Open
KotlinIsland opened this issue Apr 18, 2024 · 4 comments
Open

support pytest #311

KotlinIsland opened this issue Apr 18, 2024 · 4 comments
Labels
language server plugin feature specific to some third party module and therefore requires a plugin system pylance parity feature that exists in pylance but not pyright / bug specific to our impl of a pylance feature type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules

Comments

@KotlinIsland
Copy link
Collaborator

KotlinIsland commented Apr 18, 2024

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 KotlinIsland added language server type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules LSP: inlay hints pylance parity feature that exists in pylance but not pyright / bug specific to our impl of a pylance feature labels Apr 18, 2024
@DetachHead
Copy link
Owner

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

@KotlinIsland KotlinIsland added the plugin feature specific to some third party module and therefore requires a plugin system label Apr 19, 2024
@jorenham
Copy link
Contributor

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 🤷🏻‍♂️

@DetachHead
Copy link
Owner

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language server plugin feature specific to some third party module and therefore requires a plugin system pylance parity feature that exists in pylance but not pyright / bug specific to our impl of a pylance feature type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules
Projects
None yet
Development

No branches or pull requests

3 participants