microsoft / microsoft/pyright

Nested generic return value causes overload conflicts: reportOverlappingOverload

Open
#11,534 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

**Describe the bug**
I have a decorator which can be used with both sync and async functions (takes `Callable[P, T]` or `Callable[P, Coroutine[Any, Any, T]`) and puts result `T` into generic class in both cases. I can't write overloads for it. I was able to simplify reproducer by replacing `Callable` with just `T` and `Coroutine` with just `Awaitable`.

**Code or Screenshots**

```python
from collections.abc import Awaitable
from typing import overload

class WrapsT[T]:
v: T # pyright: ignore[reportUninitializedInstanceVariable]

# error: Overload 1 for "broken" overlaps overload 2 and returns an incompatible type (reportOverlappingOverload)
@overload
def broken[T](v: Awaitable[T]) -> Awaitable[WrapsT[T]]: ... # pyright: ignore[reportOverlappingOverload]

@overload
def broken[T](v: T) -> WrapsT[T]: ...

def broken[T](v: T | Awaitable[T]) -> WrapsT[T] | Awaitable[WrapsT[T]]:
raise Exception(str(v))

@overload
def works[T](v: Awaitable[T]) -> Awaitable[T]: ...

@overload
def works[T](v: T) -> T: ...

def works[T](v: T | Awaitable[T]) -> T | Awaitable[T]:
raise Exception(str(v))
```

Code above shows that as long as i have a single generic - only `Awaitable`, code works. If I try to wrap `WrapsT` around result it breaks. I don't see where's the conflict in my overloads.

**Version**

`1.1.411`

Contributor guide

Open the contributing guide

Research direction

Start with the minimal reproducer in the issue and run it against Pyright 1.1.411 to observe reportOverlappingOverload. Trace the overload-overlap analysis for nested generic return types, then add regression coverage showing that broken accepts both overloads without a conflict while the existing works case remains valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.