ruff/crates/ruff_python_ast/src
Dhruv Manilawala 0361021863
[red-knot] Understand typing.Callable (#16493)
## Summary

Part of https://github.com/astral-sh/ruff/issues/15382

This PR implements a general callable type that wraps around a
`Signature` and it uses that new type to represent `typing.Callable`.

It also implements `Display` support for `Callable`. The format is as:
```
([<arg name>][: <arg type>][ = <default type>], ...) -> <return type>
```

The `/` and `*` separators are added at the correct boundary for
positional-only and keyword-only parameters. Now, as `typing.Callable`
only has positional-only parameters, the rendered signature would be:

```py
Callable[[int, str], None]
# (int, str, /) -> None
```

The `/` separator represents that all the arguments are positional-only.

The relationship methods that check assignability, subtype relationship,
etc. are not yet implemented and will be done so as a follow-up.

## Test Plan

Add test cases for display support for `Signature` and various mdtest
for `typing.Callable`.
2025-03-08 03:58:52 +00:00
..
visitor Auto-generate AST boilerplate (#15544) 2025-01-17 14:23:02 -05:00
comparable.rs Respect hash-equivalent literals in iteration-over-set (#14063) 2024-11-03 18:44:52 +00:00
docstrings.rs Move Python whitespace utilities into new ruff_python_whitespace crate (#4993) 2023-06-10 00:59:57 +00:00
expression.rs Remove customizable reference enum names (#15647) 2025-01-21 13:46:31 -05:00
generated.rs Auto generate ast expression nodes (#16285) 2025-03-05 08:25:55 -05:00
helpers.rs [flake8-self] Ignore attribute accesses on instance-like variables (SLF001) (#16149) 2025-02-23 10:00:49 +00:00
identifier.rs Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
int.rs [ruff] Unnecessary cast to int (RUF046) (#14697) 2024-12-05 10:30:06 +01:00
lib.rs Use ast::PythonVersion internally in the formatter and linter (#16170) 2025-02-18 12:03:13 -05:00
name.rs Auto generate ast expression nodes (#16285) 2025-03-05 08:25:55 -05:00
node.rs Remove AstNode and AnyNode (#15479) 2025-01-17 17:11:00 -05:00
nodes.rs [red-knot] Understand typing.Callable (#16493) 2025-03-08 03:58:52 +00:00
operator_precedence.rs [internal] Move Linter OperatorPrecedence into ruff_python_ast crate (#16162) 2025-02-14 15:55:07 +01:00
parenthesize.rs Remove customizable reference enum names (#15647) 2025-01-21 13:46:31 -05:00
python_version.rs Use ast::PythonVersion internally in the formatter and linter (#16170) 2025-02-18 12:03:13 -05:00
relocate.rs Auto generate ast expression nodes (#16285) 2025-03-05 08:25:55 -05:00
script.rs bump MSRV to 1.83 (#16294) 2025-02-26 06:12:43 -08:00
statement_visitor.rs Remove Stmt::TryStar (#6566) 2023-08-14 13:39:44 -04:00
stmt_if.rs Misc. small tweaks from perusing modules (#9383) 2024-01-03 12:30:25 -05:00
str.rs Preserve triple quotes and prefixes for strings (#15818) 2025-02-04 08:41:06 -05:00
str_prefix.rs Add text_len() methods to more *Prefix enums in ruff_python_ast (#16254) 2025-02-19 14:47:07 +00:00
traversal.rs Use referencial equality in traversal helper methods (#13895) 2024-10-24 11:30:22 +02:00
types.rs Remove RefEquality (#6393) 2023-08-07 16:04:50 +00:00
visitor.rs Simplify iteration idioms (#13834) 2024-10-20 22:25:27 +01:00
whitespace.rs Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00