mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 13:18:18 +00:00
![]() This PR is changes how `reveal_type` determines what type to reveal, in a way that should be a no-op to most callers. Previously, we would reveal the type of the first parameter, _after_ all of the call binding machinery had done its work. This includes inferring the specialization of a generic function, and then applying that specialization to all parameter and argument types, which is relevant since the typeshed definition of `reveal_type` is generic: ```pyi def reveal_type(obj: _T, /) -> _T: ... ``` Normally this does not matter, since we infer `_T = [arg type]` and apply that to the parameter type, yielding `[arg type]`. But applying that specialization also simplifies the argument type, which makes `reveal_type` less useful as a debugging aid when we want to see the actual, raw, unsimplified argument type. With this patch, we now grab the original unmodified argument type and reveal that instead. In addition to making the debugging aid example work, this also makes our `reveal_type` implementation more robust to custom typeshed definitions, such as ```py def reveal_type(obj: Any) -> Any: ... ``` (That custom definition is probably not what anyone would want, since you wouldn't be able to depend on the return type being equivalent to the argument type, but still) |
||
---|---|---|
.. | ||
ruff | ||
ruff_annotate_snippets | ||
ruff_benchmark | ||
ruff_cache | ||
ruff_db | ||
ruff_dev | ||
ruff_diagnostics | ||
ruff_formatter | ||
ruff_graph | ||
ruff_index | ||
ruff_linter | ||
ruff_macros | ||
ruff_notebook | ||
ruff_options_metadata | ||
ruff_python_ast | ||
ruff_python_ast_integration_tests | ||
ruff_python_codegen | ||
ruff_python_formatter | ||
ruff_python_index | ||
ruff_python_literal | ||
ruff_python_parser | ||
ruff_python_semantic | ||
ruff_python_stdlib | ||
ruff_python_trivia | ||
ruff_python_trivia_integration_tests | ||
ruff_server | ||
ruff_source_file | ||
ruff_text_size | ||
ruff_wasm | ||
ruff_workspace | ||
ty | ||
ty_ide | ||
ty_project | ||
ty_python_semantic | ||
ty_server | ||
ty_static | ||
ty_test | ||
ty_vendored | ||
ty_wasm |