mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00

I just fixed this false negative in flake8-pyi (https://github.com/PyCQA/flake8-pyi/pull/460), and then realised ruff has the exact same bug! Luckily it's a very easy fix. (The bug is that unused protocols go undetected if they're generic.)
32 lines
448 B
Python
32 lines
448 B
Python
import typing
|
|
from typing import Protocol, TypeVar
|
|
|
|
|
|
class _Foo(object, Protocol):
|
|
bar: int
|
|
|
|
|
|
class _Bar(typing.Protocol):
|
|
bar: int
|
|
|
|
|
|
_T = TypeVar("_T")
|
|
|
|
|
|
class _Baz(Protocol[_T]):
|
|
x: _T
|
|
|
|
|
|
# OK
|
|
class _UsedPrivateProtocol(Protocol):
|
|
bar: int
|
|
|
|
|
|
# Also OK
|
|
class _UsedGenericPrivateProtocol(Protocol[_T]):
|
|
x: _T
|
|
|
|
|
|
def uses_some_private_protocols(
|
|
arg: _UsedPrivateProtocol, arg2: _UsedGenericPrivateProtocol[int]
|
|
) -> None: ...
|