ruff/crates/red_knot_python_semantic
cake-monotone c6efa93cf7
[red-knot] Handle special case returning `NotImplemented` (#17034)
## Summary

Closes #16661

This PR includes two changes:

- `NotImplementedType` is now a member of `KnownClass`
- We skip `is_assignable_to` checks for `NotImplemented` when checking
return types

### Limitation

```py
def f(cond: bool) -> int:
    return 1 if cond else NotImplemented
```

The implementation covers cases where `NotImplemented` appears inside a
`Union`.
However, for more complex types (ex. `Intersection`) it will not worked.
In my opinion, supporting such complexity is unnecessary at this point.

## Test Plan

Two `mdtest` files were updated:

- `mdtest/function/return_type.md`
- `mdtest/type_properties/is_singleton.md`

To test `KnownClass`, run:
```bash
cargo test -p red_knot_python_semantic -- types::class::
```
2025-03-30 11:06:12 -07:00
..
resources [red-knot] Handle special case returning `NotImplemented` (#17034) 2025-03-30 11:06:12 -07:00
src [red-knot] Handle special case returning `NotImplemented` (#17034) 2025-03-30 11:06:12 -07:00
tests red_knot_test: add support for diagnostic snapshotting 2025-02-05 13:02:54 -05:00
Cargo.toml [red-knot] Add a test to ensure that `KnownClass::try_from_file_and_name()` is kept up to date (#16326) 2025-02-24 12:14:20 +00:00
build.rs Modernize build scripts (#13837) 2024-10-20 22:35:35 +01:00
mdtest.py [red-knot] Fix possible TOCTOU mistake in mdtest runner (#15673) 2025-01-22 15:24:25 +00:00
mdtest.py.lock [red-knot] Markdown test runner (#15632) 2025-01-21 14:06:35 +01:00