ruff/crates/red_knot_python_semantic/resources/mdtest/annotations
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
..
annotated.md [red-knot] Emit an error if a bare Annotated or Literal is used in a type expression (#14973) 2024-12-15 02:00:52 +00:00
any.md [red-knot] Understand Annotated (#14950) 2024-12-13 09:41:37 -08:00
callable.md [red-knot] Understand typing.Callable (#16493) 2025-03-08 03:58:52 +00:00
deferred.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
int_float_complex.md [red-knot] add special case for float/complex (#16166) 2025-02-14 12:24:10 -08:00
invalid.md [red-knot] Disallow more invalid type expressions (#16427) 2025-02-28 10:04:30 +00:00
literal.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
literal_string.md [red-knot] Attribute access and the descriptor protocol (#16416) 2025-03-07 22:03:28 +01:00
never.md [red-knot] Statically known branches (#15019) 2024-12-21 11:33:10 +01:00
optional.md Understand typing.Optional in annotations (#14397) 2024-11-17 17:04:58 +00:00
starred.md [red-knot] function parameter types (#14802) 2024-12-06 12:55:56 -08:00
stdlib_typing_aliases.md [red-knot] Attribute access and the descriptor protocol (#16416) 2025-03-07 22:03:28 +01:00
string.md [red-knot] Add diagnostic for class-object access to pure instance variables (#16036) 2025-02-24 15:17:16 +01:00
union.md [red-knot] add special case for float/complex (#16166) 2025-02-14 12:24:10 -08:00
unsupported_special_forms.md [red-knot] Understand typing.Callable (#16493) 2025-03-08 03:58:52 +00:00
unsupported_type_qualifiers.md [red-knot] Initial tests for instance attributes (#15474) 2025-01-15 14:43:41 +00:00