DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
https://docs.basedpyright.com
Other
940 stars 17 forks source link

Don't display inlay hints where the rvalue is either a constructor or a cast call #588

Open FichteFoll opened 4 weeks ago

FichteFoll commented 4 weeks ago

It's a bit redundant to display inlay hints for variables when the right-hand side of the assignment is either a class instantiation or a cast because in that case the type of the variable is already written verbatim in the code. IntelliJ does the same.

Example:

from collections.abc import Coroutine
from typing import Any, cast

from aioprometheus.asgi.middleware import MetricsMiddleware
from aioprometheus.asgi.quart import metrics

# Fix type of `metrics`
cast_metrics = cast(Coroutine[Any, Any, tuple[bytes, dict[str, str]]], metrics)

i = int(2)

2024-08-16_13-14-50

Related: https://github.com/DetachHead/basedpyright/issues/138, https://github.com/DetachHead/basedpyright/issues/135

Edit: disregard that the actual type of metrics is a callable

KotlinIsland commented 4 weeks ago

Edge case:

class A:
    def __new__(cls) -> int:
        return 1
a = A()

I would expect an inlay here, due to the constructor not being typical