mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
![]() ## Summary Allow a typevar to be callable if it is bound to a callable type, or constrained to callable types. I spent some time digging into why this support didn't fall out naturally, and ultimately the reason is that we look up `__call__` on the meta type (since its a dunder), and our implementation of `Type::to_meta_type` for `Type::Callable` does not return a type with `__call__`. A more general solution here would be to have `Type::to_meta_type` for `Type::Callable` synthesize a protocol with `__call__` and return an intersection with that protocol (since for a type to be callable, we know its meta-type must have `__call__`). That solution could in principle also replace the special-case handling of `Type::Callable` itself, here in `Type::bindings`. But that more general approach would also be slower, and our protocol support isn't quite ready for that yet, and handling this directly in `Type::bindings` is really not bad. Fixes https://github.com/astral-sh/ty/issues/480 ## Test Plan Added mdtests. |
||
---|---|---|
.. | ||
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_resolver | ||
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_test | ||
ty_vendored | ||
ty_wasm |