[ty] Show constructor signature on hover by Glyphack · Pull Request #24257 · astral-sh/ruff (original) (raw)

I looked into this and Codex is partially correct!

For enum we show:

class Color(
    value: Any,
    names: None = None
)

This is basically what we previously showed with new formatting. Playground

For enum there already seem to be a todo? I found this.
If we don't deviate from the standard path we would show correct signature.


For class Movie(TypedDict): we show:

Do you think the solution would be to create a synthesized binding for TypedDict in Type::bindings? Since also for parameter checking we are not using the actual signature in validate_typed_dict_constructor maybe we can create a method that returns a synthesized binding and use it in both of these places based on the current validation logic.


I feel both of these could be another PR since I want to refactor the old behavior both in type checker and IDE. I would pick it up next if the solution for both is clear. But I included a test case with a todo for both.

As you said the str case along with the following are ok I could not reproduce:

bool(1) hover: class bool(o: object = False, /)

type("MyClass", (), {}) 
hover: class type(name: str, bases: tuple[type, ...], namespace: dict[str, Any], /, **kwds: Any)

object()
hover: class object()

property(lambda self: 42)
hover: class property(fget: ((Any, /) -> Any) | None = None, fset: ((Any, Any, /) -> None) | None = None,
fdel: ((Any, /) -> None) | None = None, doc: str | None = None)

super()
hover: class super()

TypeAliasType("Name", int)

hover: class TypeAliasType(name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec |
TypeVarTuple, ...] = ...)