mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
[ty] Use fully qualified names to distinguish ambiguous protocols in diagnostics (#20627)
This commit is contained in:
parent
803d61e21f
commit
1cf19732b9
2 changed files with 39 additions and 2 deletions
|
@ -170,6 +170,36 @@ class Container(Generic[T]):
|
|||
|
||||
## Protocols
|
||||
|
||||
### Differing members
|
||||
|
||||
`bad.py`:
|
||||
|
||||
```py
|
||||
from typing import Protocol, TypeVar
|
||||
|
||||
T_co = TypeVar("T_co", covariant=True)
|
||||
|
||||
class Iterator(Protocol[T_co]):
|
||||
def __nexxt__(self) -> T_co: ...
|
||||
|
||||
def bad() -> Iterator[str]:
|
||||
raise NotImplementedError
|
||||
```
|
||||
|
||||
`main.py`:
|
||||
|
||||
```py
|
||||
from typing import Iterator
|
||||
|
||||
def f() -> Iterator[str]:
|
||||
import bad
|
||||
|
||||
# error: [invalid-return-type] "Return type does not match returned value: expected `typing.Iterator[str]`, found `bad.Iterator[str]"
|
||||
return bad.bad()
|
||||
```
|
||||
|
||||
### Same members but with different types
|
||||
|
||||
```py
|
||||
from typing import Protocol
|
||||
import proto_a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue