ruff
7b622270 - [red-knot] Add `FunctionType::to_overloaded` (#17585)

Commit
142 days ago
[red-knot] Add `FunctionType::to_overloaded` (#17585) ## Summary This PR adds a new method `FunctionType::to_overloaded` which converts a `FunctionType` into an `OverloadedFunction` which contains all the `@overload`-ed `FunctionType` and the implementation `FunctionType` if it exists. There's a big caveat here (it's the way overloads work) which is that this method can only "see" all the overloads that comes _before_ itself. Consider the following example: ```py from typing import overload @overload def foo() -> None: ... @overload def foo(x: int) -> int: ... def foo(x: int | None) -> int | None: return x ``` Here, when the `to_overloaded` method is invoked on the 1. first `foo` definition, it would only contain a single overload which is itself and no implementation. 2. second `foo` definition, it would contain both overloads and still no implementation 3. third `foo` definition, it would contain both overloads and the implementation which is itself ### Usages This method will be used in the logic for checking invalid overload usages. It can also be used for #17541. ## Test Plan Make sure that existing tests pass.
Author
Parents
Loading